static void Main(string[] args) { WriteLine(); WriteLine("Recursive Singly Linked List"); WriteLine(); WriteLine("Time & Space Complexity - Worst Case"); WriteLine(); WriteLine("Time Complexity"); WriteLine(); WriteLine("Search - O(n)"); WriteLine(); WriteLine("Insert"); WriteLine("At Begining/ Head - O(1)"); WriteLine("At End/ Tail - O(1)"); WriteLine(); WriteLine("Remove"); WriteLine("At Begining/ Head - O(1)"); WriteLine("At End/ Tail - O(n)"); WriteLine("At A Position/ in between - O(n)"); WriteLine(); WriteLine("Space Complexity - O(n) : for using a call stack for recursive calls."); SinglyLinkedList node = new SinglyLinkedList(); node.AddToEnd(10); node.AddToEnd(20); node.AddToEnd(30); node.AddToBegining(1); node.AddToBegining(2); node.AddToEnd(40); node.Print(); int deleteNode = 2; node.deleteNode(deleteNode); WriteLine(); WriteLine($"After deleting Node {deleteNode}, LinkedList will be -"); WriteLine(); node.Print(); }
static void Main() { // declare and initialize linked list classes SinglyLinkedList singlyLinkedList = new SinglyLinkedList(); SinglyLinkedList singlyLinkedListTwo = new SinglyLinkedList(); // test, append to front of the first list and print Console.WriteLine("Adding to the front of the list:"); singlyLinkedList.AddToFront("World!"); singlyLinkedList.AddToFront("Hello"); singlyLinkedList.PrintAllNodes(); // test, append to end of the second list and print Console.WriteLine("Adding to the end of the list:"); singlyLinkedListTwo.AddToEnd("Hello"); singlyLinkedListTwo.AddToEnd("World!"); singlyLinkedListTwo.PrintAllNodes(); }