Exemple #1
0
        public void Add(int data)
        {
            var node = new DoubleNode <int>(data);

            if (Head == null)
            {
                Head = node;
            }
            else
            {
                Tail.Next     = node;
                node.Previous = Tail;
            }
            Tail = node;
            Count++;
        }
Exemple #2
0
        public void AddFirst(int data)
        {
            var node = new DoubleNode <int>(data);
            var temp = Head;

            node.Next = temp;
            Head      = node;

            if (Count == 0)
            {
                Tail = Head;
            }
            else
            {
                temp.Previous = node;
            }

            Count++;
        }
Exemple #3
0
        public bool Remove(int data)
        {
            var current = Head;

            while (current != null)
            {
                if (current.Data.Equals(data))
                {
                    break;
                }
                current = current.Next;
            }
            if (current != null)
            {
                if (current.Next != null)
                {
                    current.Next.Previous = current.Previous;
                }
                else
                {
                    Tail = current.Previous;
                }

                if (current.Previous != null)
                {
                    current.Previous.Next = current.Next;
                }
                else
                {
                    Head = current.Next;
                }

                Count--;
                return(true);
            }
            return(false);
        }
Exemple #4
0
 public void Clear()
 {
     Head  = null;
     Tail  = null;
     Count = 0;
 }