Example #1
0
 public NODE <Type> this[int i]
 {
     get {
         int         k    = 0;
         NODE <Type> temp = head;
         while (temp != null)
         {
             if (k == i)
             {
                 return(temp);
             }
             k++;
             temp = temp.next;
         }
         return(null);
     }
     set {
         int         k    = 0;
         NODE <Type> temp = head;
         while (temp != null)
         {
             if (k == i)
             {
                 temp = value;
             }
             k++;
             temp = temp.next;
         }
     }
 }
Example #2
0
        public NODE <Type> GetLastNode(SingleLinkedList <Type> singlyList)
        {
            NODE <Type> temp = singlyList.head;

            while (temp.next != null)
            {
                temp = temp.next;
            }
            return(temp);
        }
Example #3
0
        public int Count()
        {
            int         n    = 0;
            NODE <Type> temp = head;

            while (temp != null)
            {
                temp = temp.next;
                n   += 1;
            }
            return(n);
        }
Example #4
0
        public void InsertLast(SingleLinkedList <Type> singlyList, Type new_data)
        {
            NODE <Type> new_node = new NODE <Type>(new_data);

            if (singlyList.head == null)
            {
                singlyList.head = new_node;
                return;
            }
            NODE <Type> lastNode = GetLastNode(singlyList);

            lastNode.next = new_node;
        }
Example #5
0
 public NODE(T d)
 {
     data = d;
     next = null;
 }