Exemplo n.º 1
0
        public bool Remove(T data)
        {
            SimpleElement <T> current  = head;
            SimpleElement <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);
        }
Exemplo n.º 2
0
        public override string ToString()
        {
            string            str     = "";
            SimpleElement <T> current = head;

            while (current != null)
            {
                str    += " " + current.Data;
                current = current.Next;
            }
            return(str);
        }
Exemplo n.º 3
0
        public void AppendFirst(T data)
        {
            SimpleElement <T> node = new SimpleElement <T>(data);

            node.Next = head;
            head      = node;
            if (count == 0)
            {
                tail = head;
            }
            count++;
        }
Exemplo n.º 4
0
        public bool Contains(T data)
        {
            SimpleElement <T> current = head;

            while (current != null)
            {
                if (current.Data.Equals(data))
                {
                    return(true);
                }
                current = current.Next;
            }
            return(false);
        }
Exemplo n.º 5
0
        public void Add(T data)
        {
            SimpleElement <T> node = new SimpleElement <T>(data);

            if (head == null)
            {
                head = node;
            }
            else
            {
                tail.Next = node;
            }
            tail = node;
            count++;
        }
Exemplo n.º 6
0
 public void Clear()
 {
     head  = null;
     tail  = null;
     count = 0;
 }