public SingleLinkedNode <T> GetNode(int index)
        {
            if (index < 0 || index >= count)
            {
                throw new IndexOutOfRangeException("Invalid index");
            }
            SingleLinkedNode <T> current = head;

            for (int a = 0; a < count - 1; a++)
            { // loop until we're at the index
                current = current.Next;
            }
            return(current);
        }
        public void Add(T data)
        {
            SingleLinkedNode <T> node = new SingleLinkedNode <T>(data);

            if (count == 0)
            {
                head = node;
                tail = node;
            }
            else
            {
                tail.Next = node;
                tail      = node;
            }
            count++;
        }
Beispiel #3
0
 public SingleLinkedNode(T data, SingleLinkedNode <T> next)
 {
     this.data = data;
     this.next = next;
 }
Beispiel #4
0
 public SingleLinkedNode(T data)
 {
     this.data = data;
     next      = null;
 }
 public SingleLinkedList(SingleLinkedNode <T> node)
 {
     count = 1;
     head  = node;
     tail  = node;
 }
 public SingleLinkedList()
 {
     count = 0;
     head  = null;
     tail  = null;
 }
 public void Clear()
 {
     head  = null;
     tail  = null;
     count = 0;
 }