Example #1
0
        public double Summ()
        {
            Current = First;
            double res   = 0;
            uint   count = 1;

            while (Current != null)
            {
                res += Convert.ToDouble(Current.Value);
                count++;
                Current = Current.Next;
            }
            return(res);
        }
Example #2
0
        public void AddBack(T item)
        {
            DoublyNode <T> newDoublyNode = new DoublyNode <T>(item);

            if (First == null)
            {
                First = Last = newDoublyNode;
            }
            else
            {
                Last.Next          = newDoublyNode;
                newDoublyNode.Prev = Last;
                Last = newDoublyNode;
            }
            Count++;
        }
Example #3
0
        public void AddFront(T item)
        {
            DoublyNode <T> newDoublyNode = new DoublyNode <T>(item);

            if (First == null)
            {
                First = Last = newDoublyNode;
            }
            else
            {
                newDoublyNode.Next = First;
                First = newDoublyNode;
                newDoublyNode.Next.Prev = First;
            }
            Count++;
        }
Example #4
0
 public void RemoveFront()
 {
     if (First == null)
     {
         throw new InvalidOperationException();
     }
     else
     {
         DoublyNode <T> temp = First;
         if (First.Next != null)
         {
             First.Next.Prev = null;
         }
         First = First.Next;
         Count--;
     }
 }
Example #5
0
        public uint?GetIndex(T item)
        {
            uint index = 1;

            Current = First;
            while (Current.Next != null)
            {
                Current = Current.Next;
                index++;

                if (Current.Value.Equals(item))
                {
                    return(index);
                }
            }
            return(null);
        }
Example #6
0
        public void Display()
        {
            if (First == null)
            {
                Console.WriteLine("Doubly Linked List is empty");
                return;
            }
            Current = First;
            uint count = 1;

            while (Current != null)
            {
                Console.WriteLine("Element " + count.ToString() + " : " + Current.Value.ToString());
                count++;
                Current = Current.Next;
            }
        }
Example #7
0
 public void RemoveBack()
 {
     if (Last == null)
     {
         throw new InvalidOperationException();
     }
     else
     {
         DoublyNode <T> temp = Last;
         if (Last.Prev != null)
         {
             Last.Prev.Next = null;
         }
         Last = Last.Prev;
         Count--;
     }
 }
Example #8
0
 public MyDoublyLinkedList()
 {
     size  = 0;
     First = Current = Last = null;
 }