| 376 | } |
| 377 | |
| 378 | fn main() { |
| 379 | basic(); |
| 380 | order(); |
| 381 | |
| 382 | fn basic() { |
| 383 | let mut bst = BST::<i32, char>::new(); |
| 384 | bst.insert(8, 'e'); bst.insert(6,'c'); |
| 385 | bst.insert(7, 'd'); bst.insert(5,'b'); |
| 386 | bst.insert(10,'g'); bst.insert(9,'f'); |
| 387 | bst.insert(11,'h'); bst.insert(4,'a'); |
| 388 | |
| 389 | println!("bst is empty: {}", bst.is_empty()); |
| 390 | println!("bst size: {}", bst.size()); |
| 391 | println!("bst leaves: {}", bst.leaf_size()); |
| 392 | println!("bst internals: {}", bst.none_leaf_size()); |
| 393 | println!("bst depth: {}", bst.depth()); |
| 394 | |
| 395 | let min_kv = bst.min(); |
| 396 | let max_kv = bst.max(); |
| 397 | println!("min key: {:?}, min val: {:?}", min_kv.0, min_kv.1); |
| 398 | println!("max key: {:?}, max val: {:?}", max_kv.0, max_kv.1); |
| 399 | |
| 400 | println!("bst contains 5: {}", bst.contains(&5)); |
| 401 | println!("key: 5, val: {:?}", bst.get(&5).unwrap()); |
| 402 | } |
| 403 | |
| 404 | fn order() { |
| 405 | let mut bst = BST::<i32, char>::new(); |
| 406 | bst.insert(8, 'e'); bst.insert(6,'c'); |
| 407 | bst.insert(7, 'd'); bst.insert(5,'b'); |
| 408 | bst.insert(10,'g'); bst.insert(9,'f'); |
| 409 | bst.insert(11,'h'); bst.insert(4,'a'); |
| 410 | |
| 411 | println!("internal inorder, preorder, postorder: "); |
| 412 | bst.inorder(); |
| 413 | bst.preorder(); |
| 414 | bst.postorder(); |
| 415 | bst.levelorder(); |
| 416 | println!("outside inorder, preorder, postorder: "); |
| 417 | let nk = Some(Box::new(bst.clone())); |
| 418 | inorder(nk.clone()); |
| 419 | preorder(nk.clone()); |
| 420 | postorder(nk.clone()); |
| 421 | levelorder(nk.clone()); |
| 422 | } |
| 423 | } |