示例#1
0
        public bool Remove(T data)
        {
            MyClassGeneric <T> current  = head;
            MyClassGeneric <T> previous = null;

            while (current != null)
            {
                if (current.Data.Equals(data))
                {
                    if (previous != null)
                    {
                        previous.Next = current.Next;
                        if (current.Next == null)
                        {
                            tail = previous;
                        }
                    }
                    else
                    {
                        head = head.Next;
                        if (head == null)
                        {
                            tail = null;
                        }
                    }
                    count--;
                    return(true);
                }
                previous = current;
                current  = current.Next;
            }
            return(false);
        }
示例#2
0
        public IEnumerator <T> GetEnumerator()
        {
            MyClassGeneric <T> current = head;

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

                current = current.Next;
            }
        }
示例#3
0
        public void AppendFirst(T data)
        {
            MyClassGeneric <T> node = new MyClassGeneric <T> (data);

            node.Next = head;
            head      = node;
            if (count == 0)
            {
                tail = head;
            }
            count++;
        }
示例#4
0
        public bool Contains(T data)
        {
            MyClassGeneric <T> current = head;

            while (current != null)
            {
                if (current.Data.Equals(data))
                {
                    return(true);
                }
                current = current.Next;
            }
            return(false);
        }
示例#5
0
        public void Add(T data)
        {
            MyClassGeneric <T> elementMyClass = new MyClassGeneric <T>(data);

            if (head == null)
            {
                head = elementMyClass;
            }
            else
            {
                tail.Next = elementMyClass;
            }

            tail = elementMyClass;

            count++;
        }
示例#6
0
 public void Clear()
 {
     head  = null;
     tail  = null;
     count = 0;
 }