예제 #1
0
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
            CList <T> list = (CList <T>)obj;

            if (_length != list._length)
            {
                return(false);
            }
            CNode <T> node1 = _head.Next;
            CNode <T> node2 = list._head.Next;

            while (node1 != _tail)
            {
                if (!node1.Data.Equals(node2.Data))
                {
                    return(false);
                }
                node1 = node1.Next;
                node2 = node2.Next;
            }
            return(true);
        }
예제 #2
0
 public CList()
 {
     _head      = new CNode <T>();
     _tail      = new CNode <T>();
     _head.Next = _tail;
     _current   = _head;
     _length    = 0;
 }
예제 #3
0
        public void PushFront(T t)
        {
            CNode <T> newNode   = new CNode <T>(t);
            CNode <T> firstNode = _head.Next;

            newNode.Next = firstNode;
            _head.Next   = newNode;
        }
예제 #4
0
        public void Extend(CList <T> list)
        {
            CNode <T> node = list._head.Next;

            while (node != list._tail)
            {
                Append(node.Data);
                node = node.Next;
            }
        }
예제 #5
0
        public void PopFront()
        {
            if (_length == 0)
            {
                return;
            }
            CNode <T> first = _head.Next;

            _head.Next = first.Next;
            _length--;
        }
예제 #6
0
        public void Append(T t)
        {
            CNode <T> node = _head;

            while (node.Next != _tail)
            {
                node = node.Next;
            }
            CNode <T> newNode = new CNode <T>(t);

            newNode.Next = _tail;
            node.Next    = newNode;
            _length++;
        }
예제 #7
0
        public CList(CList <T> list)
        {
            Clear();
            _head      = new CNode <T>();
            _tail      = new CNode <T>();
            _head.Next = _tail;
            CNode <T> node = list._head.Next;

            while (node != list._tail)
            {
                Append(node.Data);
                node = node.Next;
            }
        }
예제 #8
0
        public int Count(T t)
        {
            int       count = 0;
            CNode <T> node  = _head.Next;

            while (node != _tail)
            {
                if (t.Equals(node.Data))
                {
                    count++;
                }
                node = node.Next;
            }
            return(count);
        }
예제 #9
0
        public int Find(T t)
        {
            int       index = 0;
            CNode <T> node  = _head.Next;

            while (node != _tail)
            {
                if (t.Equals(node.Data))
                {
                    return(index);
                }
                node = node.Next;
                index++;
            }
            return(-1);
        }
예제 #10
0
        public override string ToString()
        {
            if (_length == 0)
            {
                return("[]");
            }
            string    s    = "[";
            CNode <T> node = _head.Next;

            while (node.Next != _tail)
            {
                s   += node.Data + ", ";
                node = node.Next;
            }
            s += node.Data + "]";
            return(s);
        }
예제 #11
0
        public void PopBack()
        {
            if (this._length == 0)
            {
                return;
            }
            CNode <T> curr = _head.Next;
            CNode <T> prev = _head;

            while (curr.Next != _tail)
            {
                curr = curr.Next;
                prev = prev.Next;
            }
            prev.Next = _tail;
            _length--;
        }
예제 #12
0
        public void Reverse()
        {
            if (_length <= 1)
            {
                return;
            }
            _tail = _head;
            CNode <T> prevNode = null;
            CNode <T> currNode = _head;
            CNode <T> nextNode = null;

            while (currNode != null)
            {
                nextNode      = currNode.Next;
                currNode.Next = prevNode;
                prevNode      = currNode;
                currNode      = nextNode;
            }
            _head = prevNode;
        }
예제 #13
0
 public T this[int index]
 {
     get {
         int l = _length;
         if (l == 0)
         {
             throw new Exception("ListIsEmptyError");
         }
         if (index < 0 || index >= l)
         {
             throw new Exception("IndexOutOfBoundsError");
         }
         CNode <T> node = _head;
         int       i    = 0;
         while (i <= index)
         {
             node = node.Next;
             i++;
         }
         return(node.Data);
     }
 }
예제 #14
0
 public void Reset()
 {
     _current = _head;
 }
예제 #15
0
 public bool MoveNext()
 {
     _current = _current.Next;
     return(_current != _tail);
 }
예제 #16
0
 public CNode(T data)
 {
     _data = data;
     _next = null;
 }