Esempio n. 1
0
        internal static void InsertFrontSingly(SList list, int data)
        {
            SNode newNode = new SNode(data);

            newNode.next = list.head;
            list.head    = newNode;
        }
Esempio n. 2
0
        internal static void DeleteNodeSingly(SList list, int data)
        {
            SNode node = list.head;

            while (node.next.data != data)
            {
                node = node.next;
            }
            node.next = node.next.next;
        }
Esempio n. 3
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;
        }
Esempio n. 4
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();
        }
Esempio n. 5
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;
        }
Esempio n. 6
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;
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            //var linkedList = new LinkedList<int>();

            SList singleList = new SList();
            DList doubleList = new DList();

            //Queue q = new Queue();
            //Stack s = new Stack();

            InsertFrontSingly(singleList, 5);
            InsertFrontSingly(singleList, 10);
            InsertFrontSingly(singleList, 15);
            InsertFrontSingly(singleList, 20);
            InsertFrontSingly(singleList, 25);

            //PrintAllSingly(singleList);
            //DeleteNodeSingly(singleList, 20);
            //PrintAllSingly(singleList);

            PrintAllSingly(singleList);
            ReverseSingly(singleList);
            PrintAllSingly(singleList);

            InsertFrontDoubly(doubleList, 5);
            InsertFrontDoubly(doubleList, 10);
            InsertFrontDoubly(doubleList, 15);
            InsertFrontDoubly(doubleList, 20);
            InsertFrontDoubly(doubleList, 25);

            //PrintAllDoubly(doubleList);
            //DeleteNodeDoubly(doubleList, 20);
            //PrintAllDoubly(doubleList);

            Console.ReadLine();
        }