Exemplo n.º 1
0
        public void AddLast(T x)
        {
            var toAdd = new Node2 <T>(x);

            if (head == null)
            {
                head = toAdd;
            }
            else
            {
                tail.Next      = toAdd;
                toAdd.Previous = tail;
            }
            tail = toAdd;
            Count++;
        }
Exemplo n.º 2
0
        public void AddFirst(T x)
        {
            var toAdd = new Node2 <T>(x);

            toAdd.Next = head;
            head       = toAdd;
            if (Count == 0)
            {
                tail = head;
            }
            else
            {
                toAdd.Next.Previous = toAdd;
            }
            Count++;
        }
Exemplo n.º 3
0
 public T this[int index]
 {
     get
     {
         Node2 <T> current = head;
         for (int i = 0; i != index && current != null; i++)
         {
             current = current.Next;
         }
         return(current.Value);
     }
     set
     {
         Node2 <T> current = head;
         for (int i = 0; i != index && current != null; i++)
         {
             current = current.Next;
         }
         current.Value = value;
     }
 }
Exemplo n.º 4
0
 public void Insert(int index, T x)
 {
     if (head == null)
     {
         var toAdd = new Node2 <T>(x);
         head = toAdd;
         tail = toAdd;
     }
     else
     {
         if (index == 0)
         {
             AddFirst(x);
         }
         else if (index == Count - 1)
         {
             AddLast(x);
         }
         else
         {
             var       toAdd    = new Node2 <T>(x);
             Node2 <T> current  = head;
             Node2 <T> previous = head;
             for (int i = 0; i < index; i++)
             {
                 previous = current;
                 current  = current.Next;
             }
             previous.Next    = toAdd;
             toAdd.Previous   = previous;
             toAdd.Next       = current;
             current.Previous = toAdd;
         }
     }
     Count++;
 }
Exemplo n.º 5
0
 public void Clear()
 {
     head  = null;
     tail  = null;
     Count = 0;
 }