/// <summary> /// Removes all the empty levels leftover in the Skip List /// </summary> protected void clearEmptyLevels() { if (this.levels > 1) //more than one level, don't want to remove bottom level { SkipListNode <T> currentNode = this.topLeft; while (currentNode != this.bottomLeft) //do not remove the bottom level { if (currentNode.IsHeader() && currentNode.Next.IsFooter()) { SkipListNode <T> belowNode = currentNode.Below; //Remove the empty level //Update pointers topLeft = currentNode.Below; //Remove links currentNode.Next.Dispose(); currentNode.Dispose(); //Update counters this.levels--; currentNode = belowNode; //scan down } else { break; //a single non-emtpy level means the rest of the levels are not empty } } } }
/// <summary> /// Removes all values in the Skip List /// </summary> public virtual void Clear() { SkipListNode <T> currentNode = this.Head; while (currentNode != null) { SkipListNode <T> nextNode = currentNode.Next; //save reference to next node if (!currentNode.IsHeader() && !currentNode.IsFooter()) { this.Remove(currentNode); } currentNode = nextNode; } }