public override T Remove(T value) { Assertion.Pre(value != null); SinglyLinkedListElement <T> finger = this.head; SinglyLinkedListElement <T> previous = null; while (finger != null && !value.Equals(finger.GetValue())) { previous = finger; finger = finger.GetNext(); } if (finger == null) { return(default(T)); } if (previous == null) { this.head = finger.GetNext(); } else { previous.SetNext(finger.GetNext()); } this.count--; return(finger.GetValue()); }
public override T RemoveFromTail() { Assertion.Pre(this.tail != null); SinglyLinkedListElement <T> finger = this.tail; SinglyLinkedListElement <T> oldTail = this.tail; while (finger.GetNext() != this.tail) { finger = finger.GetNext(); } if (finger == this.tail) { this.tail = null; } else { finger.SetNext(this.tail.GetNext()); this.tail = finger; } this.count--; return(oldTail.GetValue()); }
public void Insert(T value) { Assertion.Pre(!IsValid()); BinaryTreeNode <T> node = new BinaryTreeNode <T>(value); if (root == null) { Assertion.Assert(this.prior == null); this.root = this.cursor = node; } else { Assertion.Assert(this.prior != null); if (wentLeft) { this.prior.SetLeft(this.cursor = node); } else { this.prior.SetRight(this.cursor = node); } } this.size++; }
public override T RemoveFromTail() { Assertion.Pre(this.head != null); SinglyLinkedListElement <T> previous = null; SinglyLinkedListElement <T> finger = this.head; while (finger.GetNext() != null) { previous = finger; finger = finger.GetNext(); } if (previous == null) { this.head = null; } else { previous.SetNext(finger.GetNext()); } this.count--; return(finger.GetValue()); }
public void MoveLeft() { Assertion.Pre(IsValid()); this.prior = this.cursor; this.cursor = this.cursor.GetLeft(); this.wentLeft = true; }
public void MoveUp() { Assertion.Pre(IsValid()); Assertion.Pre(HasParent()); this.prior = null; this.cursor = this.cursor.GetParent(); }
public void MoveRight() { Assertion.Pre(IsValid()); this.prior = this.cursor; this.cursor = this.cursor.GetRight(); this.wentLeft = false; }
public T Remove() { Assertion.Pre(IsValid()); Assertion.Pre(!(HasLeft() || HasRight())); T value = GetValue(); if (IsLeft()) { MoveUp(); this.cursor.SetLeft(null); } else if (IsRight()) { MoveUp(); this.cursor.SetRight(null); } else { this.root = this.cursor = this.prior = null; } this.size--; return(value); }
public override T Next() { Assertion.Pre(HasMore()); BinaryTreeNode <T> node = this.todo.Pop(); T value = node.GetValue(); if (!this.todo.IsEmpty()) { BinaryTreeNode <T> parent = this.todo.Peek(); if (node == parent.GetLeft()) { node = parent.GetRight(); while (node != null) { this.todo.Push(node); if (node.GetLeft() != null) { node = node.GetLeft(); } else { node = node.GetRight(); } } } } return(value); }
private static void Swap(int[] data, int i, int j) { Assertion.Pre(i < data.Length && j < data.Length && i >= 0 && j >= 0); int tmp = data[i]; data[i] = data[j]; data[j] = tmp; }
public override void Enqueue(T value) { Assertion.Pre(!this.IsFull()); int tail = (this.head + this.count) % this.data.Length; this.data[tail] = value; this.count++; }
public Vector <T> RemoveRowAt(int r) { Assertion.Pre(r < this.Height); Vector <T> row = this.rows.RemoveElementAt(r); return(row); }
public override T Dequeue() { Assertion.Pre(!this.IsEmpty()); T toReturn = this.data[this.head]; this.head = (this.head + 1) % this.data.Length; this.count--; return(toReturn); }
public void SetElementAt(T value, int r, int c) { Assertion.Pre(r < this.Height); Assertion.Pre(c < this.Width); Vector <T> row = this.rows.GetElementAt(r); row.SetElementAt(value, c); }
public T GetElementAt(int r, int c) { Assertion.Pre(r < this.Height); Assertion.Pre(c < this.Width); Vector <T> row = this.rows.GetElementAt(r); return(row.GetElementAt(c)); }
public void InsertColumnAt(int c) { Assertion.Pre(c < this.Width); for (int i = 0; i < this.Height; i++) { Vector <T> row = this.rows.GetElementAt(i); row.InsertElementAt(default(T), c); } }
public override T RemoveFromHead() { Assertion.Pre(this.head != null); SinglyLinkedListElement <T> oldHead = this.head; this.head = this.head.GetNext(); this.count--; return(oldHead.GetValue()); }
public void InsertRowAt(int r) { Assertion.Pre(r < this.Height); Vector <T> row = new Vector <T>(this.Width); for (int i = 0; i < this.Width; i++) { row.AddElement(default(T)); } this.rows.InsertElementAt(row, r); }
public override T PeekTail() { Assertion.Pre(this.head != null); SinglyLinkedListElement <T> finger = this.head; while (finger.GetNext() != null) { finger = finger.GetNext(); } return(finger.GetValue()); }
public override bool Contains(T value) { Assertion.Pre(value != null); SinglyLinkedListElement <T> finger = this.head; while (finger != null && !value.Equals(finger.GetValue())) { finger = finger.GetNext(); } return(finger != null); }
public Vector <T> RemoveColumnAt(int c) { Assertion.Pre(c < this.Width); Vector <T> column = new Vector <T>(); for (int i = 0; i < this.Height; i++) { Vector <T> row = this.rows.GetElementAt(i); column.AddElement(row.RemoveElementAt(c)); } return(column); }
public T RemoveElementAt(int index) { Assertion.Pre(index < this.count); this.count--; T o = this.data[index]; for (int i = index; i < this.count; i++) { this.data[i] = this.data[i + 1]; } return(o); }
public void InsertElementAt(T value, int index) { Assertion.Pre(index < this.count); EnsureCapacity(this.count + 1); for (int i = this.count; i > index; i--) { this.data[i] = this.data[i - 1]; } this.data[index] = value; this.count++; }
public override T Remove() { Assertion.Pre(!IsEmpty()); T value = Peek(); this.data.SetElementAt(this.data.GetElementAt(this.Size - 1), 0); this.data.RemoveElementAt(this.Size - 1); if (this.Size > 1) { PushDownRoot(0); } return(value); }
public override T Next() { Assertion.Pre(HasMore()); BinaryTreeNode <T> node = this.todo.Dequeue(); if (node.GetLeft() != null) { this.todo.Enqueue(node.GetLeft()); } if (node.GetRight() != null) { this.todo.Enqueue(node.GetRight()); } return(node.GetValue()); }
public override T Next() { Assertion.Pre(HasMore()); BinaryTreeNode<T> node = this.todo.Pop(); T value = node.GetValue(); node = node.GetRight(); while (node != null) { this.todo.Push(node); node = node.GetLeft(); } return value; }
public override T RemoveFromHead() { Assertion.Pre(this.head != null); DoublyLinkedListElement <T> oldHead = this.head; this.head = this.head.GetNext(); if (this.head == null) { this.tail = null; } else { this.head.SetPrevious(null); } return(oldHead.GetValue()); }
public override T RemoveFromHead() { Assertion.Pre(this.tail != null); SinglyLinkedListElement <T> head = this.tail.GetNext(); if (this.tail == head) { this.tail = null; } else { this.tail.SetNext(head.GetNext()); } this.count--; return(head.GetValue()); }
public override T RemoveFromTail() { Assertion.Pre(this.tail != null); DoublyLinkedListElement <T> oldTail = this.tail; this.tail = this.tail.GetPrevious(); if (this.tail == null) { this.head = null; } else { this.tail.SetNext(null); } return(oldTail.GetValue()); }
public override bool Contains(T value) { Assertion.Pre(value != null); SinglyLinkedListElement <T> finger = this.tail; if (finger == null) { return(false); } do { if (value.Equals(finger.GetValue())) { return(true); } finger = finger.GetNext(); } while (finger != this.tail); return(false); }