Skip to content

Instantly share code, notes, and snippets.

@bstrie
Forked from garrickp/Comparison Problem
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bstrie/b81bece885e637e73dde to your computer and use it in GitHub Desktop.
Save bstrie/b81bece885e637e73dde to your computer and use it in GitHub Desktop.
#[deriving(PartialEq)]
enum Ordering {
Less,
Equal,
Greater,
}
fn cmp(a: int, b: int) -> Ordering {
if a < b { Less }
else if a > b { Greater }
else { Equal }
}
fn main() {
let x = 5i;
let y = 6i;
let ordering = cmp(x, y);
if ordering == Less {
println!("less");
} else if ordering == Equal {
println!("equal");
} else {
println!("greater");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment