Example #1
0
 public void Remove(int index)
 {
     if (index < 0 || index >= count)
     {
         throw new IndexOutOfRangeException("ERROR: Invalid index specified. No object exists for index " + index + "!");
     }
     if (index == 0)
     {
         head = head.Next;
     }
     if (index == count - 1)
     {
         tail = GetNode(count - 2);
     }
     if (count == 1)
     {
         head = null;
         tail = null;
     }
     else
     {
         CustomLinkedNode <T> before = GetNode(index - 1);
         before.Next = before.Next.Next;
         count--;
     }
 }
Example #2
0
        public T GetData(int index)
        {
            CustomLinkedNode <T> current = head;

            for (int a = 0; a < index; a++)
            {
                current = current.Next;
            }
            return(current.Data);
        }
Example #3
0
        public CustomLinkedNode <T> GetNode(int index)
        {
            if (index < 0 || index >= count)
            {
                throw new IndexOutOfRangeException("Invalid index");
            }
            CustomLinkedNode <T> current = head;

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

            // determine if the list is empty
            // or has a bunch of nodes already
            if (count == 0)
            {
                head = n;
                tail = n;
            }
            else
            {
                tail.Next = n;
                tail      = n;
            }
            count++;
        }
Example #5
0
 public CustomLinkedNode(T data, CustomLinkedNode <T> next)
 {
     this.data = data;
     this.next = next;
 }
Example #6
0
 public CustomLinkedNode(T data)
 {
     this.data = data;
     next      = null;
 }
Example #7
0
 public CustomLinkedList()
 {
     count = 0;
     head  = null;
     tail  = null;
 }
Example #8
0
 public void Clear()
 {
     head  = null;
     tail  = null;
     count = 0;
 }