public void Add(T value)
        {
            int theHeight = ChooseRandomHeight(maxHeight);

            if (theHeight > head.Height)
            {
                //resize the array
                SkipListNode <T>[] temp = new SkipListNode <T> [theHeight];
                for (int i = 0; i < head.Height; i++)
                {
                    temp[i] = head.neighbors[i];
                }
                head.neighbors = temp;
            }


            SkipListNode <T> toInsert = new SkipListNode <T>(value, theHeight);

            for (int level = 0; level < theHeight; level++)
            {
                SkipListNode <T> temp = head;
                while (temp.neighbors[level] != null && temp.neighbors[level].Value.CompareTo(value) < 0)
                {
                    temp = temp.neighbors[level];
                }
                if (temp.neighbors[level] != null)
                {
                    toInsert.neighbors[level] = temp.neighbors[level];
                }
                temp.neighbors[level] = toInsert;
            }
        }
        public SkipList()
        {
            SkipListNode <T> actualHead = new SkipListNode <T>(default(T), 1);

            actualHead.neighbors = new SkipListNode <T> [1];
            head = actualHead;
        }
        public bool Remove(T value)
        {
            bool             hasRemoved = false;
            int              theHeight  = head.Height - 1;
            SkipListNode <T> temp       = head;

            for (int level = theHeight; level >= 0; level--)
            {
                while (temp.neighbors[level] != null && temp.neighbors[level].Value.CompareTo(value) < 0)
                {
                    temp = temp.neighbors[level];
                }
                if (temp.neighbors[level] != null && temp.neighbors[level].Value.CompareTo(value) == 0)
                {
                    temp.neighbors[level] = temp.neighbors[level].neighbors[level];
                    hasRemoved            = true;
                }
            }

            return(hasRemoved);
        }
 public void Clear()
 {
     head = null;
 }