Posts

Showing posts with the label Circular Single Linked List

Circular Single Linked List - All operations

Image
  // the 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 the linked list     Node head;     Node tail;   // function to add a new node at last of linked list // Time Complexity - O(1) , Space Complexity - O(1)     public void addNode(int x){         Node newNode = new Node(x);               if(head==null){             head=newNode;             tail=newNode;             tail.next=head;             return;         }         // else         tail.next=newNode;     ...