Example #1
0
        internal static void InsertNextToSingly(SList list, SNode prev, int data)
        {
            SNode prevNode = list.head;
            SNode node     = new SNode(data);

            while (prevNode.data != prev.data)
            {
                prevNode = prevNode.next;
            }
            node.next     = prev.next;
            prevNode.next = node;
        }
Example #2
0
        internal static void PrintAllSingly(SList list)
        {
            SNode node = list.head;

            Console.WriteLine("Singly Linked List:");
            while (node.next != null)
            {
                Console.Write(node.data + " ");
                node = node.next;
            }
            Console.Write(node.data);
            Console.WriteLine();
        }
Example #3
0
        internal static void InsertBackSingly(SList list, int data)
        {
            SNode newNode = new SNode(data);

            newNode.next = null;
            SNode node = list.head;

            while (node.next != null)
            {
                node = node.next;
            }

            node.next = newNode;
        }
Example #4
0
        internal static void ReverseSingly(SList list)
        {
            SNode prev    = null;
            SNode current = list.head;
            SNode next    = null;

            while (current != null)
            {
                next         = current.next; // Get the next node
                current.next = prev;         // Reverse the pointer of the current node
                prev         = current;      // Make the current node as previous for next iteration
                current      = next;         // Move the current pointer to next pointer
            }
            list.head = prev;
        }
Example #5
0
 public SNode(int data)
 {
     this.data = data;
     next      = null;
 }