forked from iBrizAcademy/blockchain-with-rust-dec-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Saurya P
committed
Dec 22, 2021
1 parent
520401e
commit 4057a0c
Showing
8 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("Hello World Saurya"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
fn main() { | ||
|
||
let mut arr: [i32; 5] = [5, 6, 3, 1, 10]; | ||
let mut j =0; | ||
|
||
println!("Before {:?}", arr); | ||
loop { | ||
|
||
if arr[j] > arr[j+1] | ||
{ | ||
bubbleswap(&mut arr); | ||
j =0; | ||
|
||
}else{ | ||
j = j+1; | ||
} | ||
|
||
if j >=4 { | ||
println!("After {:?}", arr); | ||
break; | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
fn bubbleswap(arr:&mut [i32; 5]) { | ||
let mut x = 0; | ||
for i in 0..arr.len()-1{ | ||
|
||
if arr[i] > arr[i+1] | ||
{ | ||
println!("{} is great than {}", arr[i], arr[i+1]); | ||
x = arr[i]; | ||
arr[i] = arr[i+1]; | ||
arr[i+1] = x; | ||
} | ||
} | ||
|
||
// println!("{:?}", arr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
fn main() { | ||
let word1:&str = "helodi"; | ||
let word2:&str = "olehdi"; | ||
|
||
println!("The strings {} and {} are {} anagrams", word1, word2, checkanagram(word1, word2)); | ||
} | ||
|
||
fn checkanagram(word1:&str, word2:&str) -> bool { | ||
let mut c = 0; | ||
|
||
if word1.len() > word2.len() { | ||
return false | ||
}else { | ||
for i in word1.chars(){ | ||
for j in word2.chars(){ | ||
|
||
|
||
if i == j { | ||
|
||
c = c+1; | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
|
||
|
||
if c == word1.len(){ | ||
return true | ||
}else { | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Program to pass ownership of a struct object, to a method and then returning it. | ||
|
||
#[derive(Debug)] | ||
struct Company { | ||
name: String, | ||
ceo: String, | ||
age: i32 | ||
} | ||
|
||
fn main() { | ||
|
||
let c1 = Company { | ||
name: String::from("XYZ"), | ||
ceo: String::from("Xi Ping"), | ||
age: 40 | ||
}; | ||
|
||
let c2 = ownershiptransfer(c1); | ||
println!("{:?}", c2); | ||
|
||
} | ||
|
||
fn ownershiptransfer(c3:Company) -> Company { | ||
println!("Function call - Ownership Transfer"); | ||
return c3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Program to pass struct variable as reference and dereferencing to modify value of object | ||
|
||
#[derive(Debug)] | ||
struct Company { | ||
name: String, | ||
ceo: String, | ||
age: i32 | ||
} | ||
|
||
fn main() { | ||
|
||
let mut c1 = Company { | ||
name: String::from("XYZ"), | ||
ceo: String::from("Xi Ping"), | ||
age: 40 | ||
}; | ||
println!("Before Referencing {:?}", c1); | ||
|
||
ownershiptransfer(&mut c1); | ||
println!("After Referencing {:?}", c1); | ||
|
||
} | ||
|
||
fn ownershiptransfer(c1:&mut Company) { | ||
(*c1).name = String::from("ABC"); | ||
(*c1).age = 30; | ||
|
||
} |
Binary file not shown.