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
/* Exercise: Loops and Functions #43 */ | |
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func Sqrt(x float64) float64 { | |
z := float64(2.) |
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
fn main() { | |
let names = vec!["Bob", "Frank", "Ferris"]; | |
for name in names.iter() { | |
match name { | |
&"Ferris" => println!("There is a rustacean among us!"), | |
_ => println!("Hello {}", name), | |
} | |
} | |
let mut names2 = vec!["Bob", "Frank", "Ferris"]; |
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
import java.util.HashSet; | |
import java.util.Objects; | |
import java.util.Set; | |
import java.util.Stack; | |
public class FloodFill { | |
private static final String SEPARATOR = "--------------------------------------------------------------------"; | |
private static final int[][] directions = new int[][]{ |
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
fn main() { | |
let rows=3; | |
let cols=4; | |
let mut state = [[ 0u8; 4]; 2]; | |
//let mut state = [[0u8; 4]; 5]; | |
state[0][1] = 42; | |
//println!("{:?}",state); | |
for (r,v) in state.iter().enumerate(){ | |
println!("{:?}",v); | |
} |
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
fn main() { | |
let mut val1 = 2; | |
val1 = 3; // OK | |
let val2 = 2; | |
//val2 = 3; // error: re-assignment of immutable variable | |
let val1 = &mut 2; | |
*val1 = 3; // OK | |
println!("Hello, world!"); |
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
fn foo(b: &mut u64) { | |
let x = &mut *b; | |
*x=52; | |
} | |
fn main() { | |
let mut x = 42; | |
foo(&mut x); | |
println!("{}",x); | |
let mut s1=5;//String::from("aa"); |
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
fn rotate_one(arr: &mut [i32]) { | |
//arr[1] = 10; | |
let c=arr.len(); | |
let first=arr[0]; | |
let mut i=1; | |
while i<c{ | |
arr[i-1]=arr[i]; | |
i+=1; | |
} | |
arr[c-1]=first; |
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
fn find_missing(arr1:&[i32],arr2:&[i32])->Vec<i32>{ | |
let mut n:Vec<i32>=Vec::new(); | |
//let v: Vec<i32> = Vec::new(); | |
let mut b:&[i32]=arr1; | |
let mut s:&[i32]=arr2; | |
if(arr2.len()>arr1.len()){ | |
b=arr2; | |
s=arr1; | |
} | |
let mut flag=true; |
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
fn rotate_one(arr: &mut [i32]) { | |
//arr[1] = 10; | |
let c=arr.len(); | |
let first=arr[0]; | |
let mut i=1; | |
while i<c{ | |
arr[i-1]=arr[i]; | |
i+=1; | |
} | |
arr[c-1]=first; |
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
fn change(mut arr:[i32;6]){ | |
arr[0]=234; | |
let p=&arr; | |
//println!("into change address {:p}",p); | |
//println!("into cahange is {:?}", arr); | |
} | |
struct Point{ | |
x:i32, | |
y:i32, | |
} |
OlderNewer