Exemplo n.º 1
0
        /// <summary>
        /// Конструктор с датой
        /// </summary>
        /// <param name="data"></param>
        public DoubleList(T data)
        {
            var item = new DoubleItem <T>(data);

            Head  = item;
            Tail  = item;
            count = 1;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Задний нумератор
        /// </summary>
        /// <returns></returns>
        public IEnumerable <T> BackEnumerator()
        {
            DoubleItem <T> current = Tail;

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

                current = current.Previous;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Поиск
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool Contains(T data)
        {
            DoubleItem <T> current = Head;

            while (current != null)
            {
                if (current.Data.Equals(data))
                {
                    return(true);
                }
                current = current.Next;
            }

            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Добавить коллекцию элемент на 1 место
        /// </summary>
        /// <param name="data"></param>
        public void AddFirst(T data)
        {
            DoubleItem <T> item = new DoubleItem <T>(data);
            DoubleItem <T> temp = Head;

            item.Next = temp;
            Head      = item;
            if (count == 0)
            {
                Tail = Head;
            }
            else
            {
                temp.Previous = item;
            }
            count++;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Добавить в коллекцию
        /// </summary>
        /// <param name="data"></param>
        public void Add(T data)
        {
            var item = new DoubleItem <T>(data);

            if (Head == null)
            {
                Head = item;
            }
            else
            {
                Tail.Next     = item;
                item.Previous = Tail;
            }

            Tail = item;
            count++;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Удаление элементов
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool Delete(T data)
        {
            DoubleItem <T> 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);
        }