Ejemplo n.º 1
0
        public IEnumerator <T> GetEnumerator()
        {
            DoublyItem <T> current = head;

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

                current = current.Next;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Добавление элемента
        /// </summary>
        /// <param name="data"></param>
        public void Add()
        {
            var node = new DoublyItem <DoublyList <T> >(new DoublyList <T>());

            if (head == null)
            {
                head = node;
            }
            else
            {
                tail.Next     = node;
                node.Previous = tail;
            }
            tail = node;
            count++;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Добавление элемента
        /// </summary>
        /// <param name="data"></param>
        public void Add(T data)
        {
            DoublyItem <T> node = new DoublyItem <T>(data);

            if (head == null)
            {
                head = node;
            }
            else
            {
                tail.Next     = node;
                node.Previous = tail;
            }
            tail = node;
            count++;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Удаление заданного элемента
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool Remove(int index)
        {
            if (index < 1 || index > count)
            {
                Console.WriteLine("Элемента с заданным индексом нет!");
                return(false);
            }

            var current = head;

            for (var i = index - 1; i > 0; i--)
            {
                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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Удаление заданного элемента
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool Remove(T data)
        {
            DoublyItem <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);
        }