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

            while (current != null)
            {
                str    += current.Data;
                current = current.Next;
            }
            return(str);
        }
Esempio n. 3
0
        public void AppendFirst(string data)
        {
            SimpleElement node = new SimpleElement(data);

            node.Next = head;
            head      = node;
            if (count == 0)
            {
                tail = head;
            }
            count++;
        }
Esempio n. 4
0
        public int Contains(string data)
        {
            SimpleElement current = head;

            while (current != null)
            {
                if (current.Data.Equals(data))
                {
                    return(current.Key);
                }
                current = current.Next;
            }
            return(0);
        }
Esempio n. 5
0
        public void Add(string data)
        {
            SimpleElement node = new SimpleElement(data);

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