This crate contains implementations of different data-structures:
```rust use project::datastructures::heap::Heap; use project::datastructures::heap::MinH;
let mut heap = MinH::default();
heap.insert(3); heap.insert(1); heap.insert(2);
asserteq!(heap.remove(), 1); asserteq!(heap.remove(), 2); assert_eq!(heap.remove(), 3); ```
```rust use project::datastructures::heap::Heap; use project::datastructures::heap::MaxH;
let mut heap = MaxH::default();
heap.insert(1); heap.insert(2); heap.insert(3);
asserteq!(heap.remove(), 3); asserteq!(heap.remove(), 2); assert_eq!(heap.remove(), 1); ```
```rust use project::datastructures::linear::LLStack; use project::datastructures::linear::LL;
let mut stack = LLStack::default();
stack.push(1); stack.push(2); stack.push(3);
asserteq!(stack.pop(), Some(3)); asserteq!(stack.pop(), Some(2)); asserteq!(stack.pop(), Some(1)); asserteq!(stack.pop(), None); ```
```rust use project::datastructures::linear::LLQueue; use project::datastructures::linear::LL;
let mut stack = LLQueue::default();
stack.push(1); stack.push(2); stack.push(3);
asserteq!(stack.pop(), Some(1)); asserteq!(stack.pop(), Some(2)); asserteq!(stack.pop(), Some(3)); asserteq!(stack.pop(), None); ```
```rust use project::datastructures::linear::DLL; use project::datastructures::linear::LL;
let mut ll = DLL::default();
ll.inserthead(1); ll.insert(2, 1); ll.insertsorted(3);
let mut iter = ll.iter(); asserteq!(iter.next(), Some(&1)); // Get current, move cursor forward asserteq!(iter.next(), Some(&2)); asserteq!(iter.nextback(), Some(&3)); // Get current, move cursor back asserteq!(iter.nextback(), Some(&2)); // Get current, move cursor back asserteq!(iter.next(), Some(&1)); asserteq!(iter.next(), Some(&2)); asserteq!(iter.next(), Some(&3)); asserteq!(iter.next(), None); ```
```rust use project::datastructures::linear::LL; use project::datastructures::linear::SLL;
let mut ll = SLL::default();
ll.inserthead(1); ll.insert(2, 1); ll.insertsorted(3);
let mut iter = ll.iter();
asserteq!(iter.next(), Some(&1)); // Get current, move cursor forward asserteq!(iter.next(), Some(&2)); asserteq!(iter.next(), Some(&3)); asserteq!(iter.next(), None); ```
```rust use project::datastructures::linear::CDLL; use project::datastructures::linear::LL;
let mut ll = CDLL::default();
ll.inserthead(1); ll.insert(2, 1); ll.insertsorted(3);
let mut iter = ll.iter();
asserteq!(iter.next(), Some(&1)); // Get current, move cursor forward asserteq!(iter.next(), Some(&2)); asserteq!(iter.next(), Some(&3)); asserteq!(iter.next(), Some(&1)); asserteq!(iter.next(), Some(&2)); asserteq!(iter.nextback(), Some(&3)); // Get current, move cursor back asserteq!(iter.nextback(), Some(&2)); // Get current, move cursor back asserteq!(iter.nextback(), Some(&1)); // Get current, move cursor back asserteq!(iter.nextback(), Some(&3)); // Get current, move cursor back asserteq!(iter.next(), Some(&2)); asserteq!(iter.next(), Some(&3)); asserteq!(iter.next(), Some(&1)); ```
```rust use project::datastructures::linear::CSLL; use project::datastructures::linear::LL;
let mut ll = CSLL::default();
ll.inserthead(1); ll.insert(2, 1); ll.insertsorted(3);
let mut iter = ll.iter();
asserteq!(iter.next(), Some(&1)); // Get current, move cursor forward asserteq!(iter.next(), Some(&2)); asserteq!(iter.next(), Some(&3)); asserteq!(iter.next(), Some(&1)); asserteq!(iter.next(), Some(&2)); asserteq!(iter.next(), Some(&3)); assert_eq!(iter.next(), Some(&1)); ```
```rust use project::datastructures::trees::BST;
let mut tree = BST::default();
tree.insert(3); tree.insert(2); tree.insert(4); tree.insert(1);
// 3 // / \ // 2 4 // / // 1 asserteq!(tree.traverseinorder(), [&1, &2, &3, &4]); asserteq!(tree.traversebreadthfirst(), [&3, &2, &4, &1]);
assert_eq!(tree.delete(&4), Some(4));
// 3 // / // 2 // / // 1 asserteq!(tree.traverseinorder(), [&1, &2, &3]); asserteq!(tree.traversebreadthfirst(), [&3, &2, &1]); ```
```rust use project::datastructures::trees::AVL;
let mut tree = AVL::default();
tree.insert(3); tree.insert(2); tree.insert(4); tree.insert(1);
// 3 // / \ // 2 4 // / // 1 asserteq!(tree.traverseinorder(), [&1, &2, &3, &4]); asserteq!(tree.traversebreadthfirst(), [&3, &2, &4, &1]);
assert_eq!(tree.delete(&4), Some(4));
// 2 // / \ // 1 3 asserteq!(tree.traverseinorder(), [&1, &2, &3]); asserteq!(tree.traversebreadthfirst(), [&2, &1, &3]); ```