Posts

Showing posts with the label Single Linked List

Single Linked List - All Operations

Image
  // the single linked list node class Node{     int data;     Node next;     Node(int x){         this.data=x;         this.next=null;     } } public class Main {       // head and tail of linked list     // we are maintaining a tail pointer too, as it helps us in inserting at the last of linked list very //easy     Node head;     Node tail;       // function to add a new node in linked list    // Time Complexity - O(1) , Space Complexity - O(1)      public void addNode(int x){         // create a new node with data x,  Time Complexity - O(1) , Space Complexity - O(1)          Node newNode = new Node(x);               // if linked list is empty         if(head==null){     ...