Esempio n. 1
0
        /// <summary>
        /// Passing through the list from end to beginning
        /// </summary>
        /// <returns>reverse transfer</returns>
        //way in other side
        public IEnumerator <T> BackEnumerator()
        {
            DoulbyUnit <T> actual = tail;

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

                actual = actual.Previous;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Passing through the list from the beginning to the end
        /// </summary>
        /// <returns>enumeration</returns>
        //way in one side
        public IEnumerator <T> GetEnumerator()
        {
            DoulbyUnit <T> actual = head;

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

                actual = actual.Next;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Determines whether a given value is a list item
        /// </summary>
        /// <param name="data">Generic type, the search value in the list</param>
        /// <returns></returns>
        public bool Contains(T data)
        {
            DoulbyUnit <T> actual = head;

            while (actual != null)
            {
                if (actual.Data.Equals(data))
                {
                    return(true);
                }
                actual = actual.Next;
            }
            return(false);
        }
Esempio n. 4
0
        /// <summary>
        /// Adds an element to the end of the list
        /// </summary>
        /// <param name="data">Generic type, the added element</param>
        public void Add(T data)
        {
            DoulbyUnit <T> _doulbyUnit = new DoulbyUnit <T>(data);

            if (head == null)
            {
                head = _doulbyUnit;
            }
            else
            {
                tail.Next     = _doulbyUnit;
                tail.Previous = tail;
            }
            tail = _doulbyUnit;
            count++;
        }
Esempio n. 5
0
        /// <summary>
        /// Adds an element to the head of the list
        /// </summary>
        /// <param name="data">Generic type, the added element</param>
        public void AddFirst(T data)
        {
            DoulbyUnit <T> _unit = new DoulbyUnit <T>(data);
            DoulbyUnit <T> temp  = head;

            _unit.Next = temp;
            head       = _unit;
            if (count == 0)
            {
                tail = head;
            }
            else
            {
                temp.Previous = _unit;
            }
            count++;
        }
Esempio n. 6
0
        /// <summary>
        /// Deletes the specified item from the linked list
        /// </summary>
        /// <param name="data">Generic type, item to remove</param>
        /// <returns></returns>
        public bool Remove(T data)
        {
            DoulbyUnit <T> actual = head;
            DoulbyUnit <T> prior  = null;

            //search element for delete - method Contains
            while (actual != null)
            {
                if (actual.Data.Equals(data))
                {
                    break;
                }
                actual = actual.Next;
            }
            if (actual != null)
            {
                //if element not last
                if (actual.Next != null)
                {
                    actual.Next.Previous = actual.Previous;
                }
                else
                {
                    //if element last
                    tail = actual.Previous;
                }

                //if element not first
                if (actual.Previous != null)
                {
                    actual.Previous.Next = actual.Next;
                }
                else
                {
                    //if - first
                    head = actual.Next;
                }

                count--;
                return(true);
            }
            return(false);
        }
Esempio n. 7
0
 /// <summary>
 /// Delete elements from LinkedList
 /// </summary>
 public void Clear()
 {
     head  = null;
     tail  = null;
     count = 0;
 }