Esempio n. 1
0
        public bool Push(Tkey element, out UStackKeyValue <Tkey, Tvalue> result)
        {
            if (first == null)
            {
                first = new UStackNode <UStackKeyValue <Tkey, Tvalue> >(new UStackKeyValue <Tkey, Tvalue>()
                {
                    key = element
                });
                end = first;

                result = end.item;
                return(true);
            }
            var e = BackFind(element);

            if (e != null)
            {
                if (e != end)
                {
                    if (e == first)
                    {
                        first = e.next;
                    }
                    else
                    {
                        e.previous.next = e.next;
                    }
                    end.next = e;
                    end      = e;
                }
                result = end.item;
                return(false);
            }
            else
            {
                end.next = new UStackNode <UStackKeyValue <Tkey, Tvalue> >(new UStackKeyValue <Tkey, Tvalue>()
                {
                    key = element
                });
                end = end.next;

                result = end.item;
                return(true);
            }
        }
Esempio n. 2
0
        public int RemoveWhile(Predicate <Tvalue> predicate)
        {
            int i = 0;

            while (first != null)
            {
                if (!predicate(first.item.value))
                {
                    goto exit;
                }
                i++;
                first = first.next;
            }
            end = first;

exit:
            return(i);
        }
Esempio n. 3
0
 void Remove(UStackNode <UStackKeyValue <Tkey, Tvalue> > element)
 {
     if (element == end)
     {
         if (element == first)
         {
             first = end = null;
         }
         else
         {
             end = element.previous;
         }
     }
     else if (element == first)
     {
         first = element.next;
     }
     else
     {
         element.previous.next = element.next;
     }
 }