예제 #1
0
        //Метод удаления элемента из списка
        public void Delete(T data)
        {
            DuplexPoint <T> current = Head;

            while (current != null)
            {
                if (current.Data.Equals(data))
                {
                    if (Head.Previous != null)
                    {
                        current.Previous.Next = current.Next;
                        current.Next.Previous = current.Previous;
                        Count--;
                        return;
                    }
                    else
                    {
                        Head          = current.Next;
                        Head.Previous = null;
                        Count--;
                        return;
                    }
                }

                current = current.Next;
            }

            Console.WriteLine("Элемент не найден!");
        }
예제 #2
0
        //Обычный метод подсчета элементов в листе
        static int Count(DuplexPoint <int> point, int count)
        {
            count++;

            while (point.Next != null)
            {
                count++;
                point = point.Next;
            }
            return(count);
        }
예제 #3
0
        //Рекурсивный метод подсчета элементов в листе
        static int CountRec(DuplexPoint <int> point, int count)
        {
            count++;

            if (point.Next == null)
            {
                return(count);
            }

            return(CountRec(point.Next, count));
        }
예제 #4
0
        //Метод добавления элемента в список
        public void Add(T data)
        {
            DuplexPoint <T> item = new DuplexPoint <T>(data);

            if (Count == 0)
            {
                SetHeadAndTail(item);
            }
            else
            {
                Tail.Next     = item;
                item.Previous = Tail;
                Tail          = item;
                Count++;
            }
        }
예제 #5
0
        public LinkedList(T data)
        {
            DuplexPoint <T> item = new DuplexPoint <T>(data);

            SetHeadAndTail(item);
        }
예제 #6
0
 public DuplexPoint(T data)
 {
     Data     = data;
     Next     = null;
     Previous = null;
 }
예제 #7
0
 public DuplexPoint()
 {
     Next     = null;
     Previous = null;
     Data     = default(T);
 }
예제 #8
0
 private void SetHeadAndTail(DuplexPoint <T> item)
 {
     Head  = item;
     Tail  = item;
     Count = 1;
 }