示例#1
0
        public void AddBefore(T value, T addValue)
        {
            NodeDouble <T> current = Head;

            while (current != null)
            {
                if (current.Value.Equals(value))
                {
                    NodeDouble <T> previos = current.Previos;
                    if (previos == null)
                    {
                        Head            = new NodeDouble <T>(addValue);
                        Head.Next       = current;
                        current.Previos = Head;
                    }
                    else
                    {
                        previos.Next         = new NodeDouble <T>(addValue);
                        previos.Next.Next    = current;
                        previos.Next.Previos = previos;
                        current.Previos      = previos.Next;
                    }
                    Count++;
                    return;
                }
                current = current.Next;
            }
        }
示例#2
0
        public void AddAfter(T value, T addValue)
        {
            NodeDouble <T> current = Head;

            while (current != null)
            {
                if (current.Value.Equals(value))
                {
                    NodeDouble <T> temp = current.Next;
                    current.Next         = new NodeDouble <T>(addValue);
                    current.Next.Previos = current;
                    if (temp != null)
                    {
                        current.Next.Next = temp;
                    }
                    else
                    {
                        Tail = current.Next;
                    }
                    Count++;
                    return;
                }
                current = current.Next;
            }
        }
示例#3
0
        public IEnumerator <T> GetEnumerator()
        {
            NodeDouble <T> current = Head;

            while (current != null)
            {
                yield return(current.Value);

                current = current.Next;
            }
        }
示例#4
0
        public void AddFirst(T value)
        {
            NodeDouble <T> node = new NodeDouble <T>(value);

            if (Head != null)
            {
                Head.Previos = node;
                node.Next    = Head;
            }
            Head = node;
            Count++;
            Tail = Tail ?? Head;
            //if (tail == null) tail = head;
        }
示例#5
0
        public T[] CopyToArray()
        {
            T[]            arr     = new T[Count];
            NodeDouble <T> current = Head;
            int            counter = 0;

            while (current != null)
            {
                arr[counter] = current.Value;
                counter++;
                current = current.Next;
            }
            return(arr);
        }
示例#6
0
        public bool Contains(T value)
        {
            NodeDouble <T> current = Head;

            while (current != null)
            {
                if (current.Value.Equals(value))
                {
                    return(true);
                }
                current = current.Next;
            }
            return(false);
        }
示例#7
0
 public void AddFirst(T value)
 {
     if (Count == 0)
     {
         Tail = Head = new NodeDouble <T>(value);
     }
     else if (Count > 0)
     {
         NodeDouble <T> temp = new NodeDouble <T>(value);
         temp.Next    = Head;
         Head.Previos = temp;
         Head         = Head.Previos;
     }
     Count++;
 }
示例#8
0
        public void AddLast(T value)
        {
            NodeDouble <T> node = new NodeDouble <T>(value);

            if (Head == null)
            {
                Head = Tail = node;
            }
            else
            {
                Tail.Next    = node;
                node.Previos = Tail;
                Tail         = node;
            }
            Count++;
        }
示例#9
0
 public void RemoveLast()
 {
     if (Tail != null)
     {
         if (Tail.Previos == null)
         {
             Clear();
         }
         else
         {
             Tail.Previos.Next = null;
             Tail = Tail.Previos;
             Count--;
         }
     }
 }
示例#10
0
        public void AddLast(T value)
        {
            if (Count == 0)
            {
                Tail = Head = new NodeDouble <T>(value);
            }

            else if (Count > 0)
            {
                NodeDouble <T> temp = new NodeDouble <T>(value);
                Tail.Next    = temp;
                temp.Previos = Tail;
                Tail         = Tail.Next;
            }
            Count++;
        }
示例#11
0
 public T GetFirst()
 {
     if (Count > 1)
     {
         T value = Head.Value;
         Head         = Head.Next;
         Head.Previos = null;
         Count--;
         return(value);
     }
     else if (Count == 1)
     {
         T value = Tail.Value;
         Tail = Head = null;
         Count--;
         return(value);
     }
     else
     {
         throw new IndexOutOfRangeException("Deck is empty");
     }
 }
示例#12
0
        public bool Remove(T value)
        {
            NodeDouble <T> current = Head;

            while (current != null)
            {
                if (current.Value.Equals(value))
                {
                    if (current.Previos == null)
                    {
                        Head = current.Next;
                        if (Head != null)
                        {
                            Head.Previos = null;
                        }
                        else
                        {
                            Tail = null;
                        }
                    }
                    else if (current.Next == null)
                    {
                        Tail      = current.Previos;
                        Tail.Next = null;
                    }
                    else
                    {
                        current.Previos.Next = current.Next;
                        current.Next.Previos = current.Previos;
                    }
                    Count--;
                    return(true);
                }
                current = current.Next;
            }

            return(false);
        }
示例#13
0
 public void Clear()
 {
     Head  = Tail = null;
     Count = 0;
 }
示例#14
0
 public void Clear()
 {
     Tail  = Head = null;
     Count = 0;
 }