Posts

Showing posts with the label linked list

Find left middle element in even size linked list in java.

■》 Code link πŸ”—-> click πŸ‘‡πŸ‘‡πŸ‘‡ https://www.programiz.com/online-compiler/1lOrmNP05XxF8 ■》 program-> import java.util.Scanner; class Node{     int val;     Node next;     Node(int val){         this.val=val;     } } class Sll{     Node head;     Node tail;     int size;     void insertAtEnd(int val){     Node temp = new Node(val);     if(head==null) head=tail=temp;     else       {         tail.next=temp;         tail=temp;        }        size++;     }     void display(){         Node temp=head;         while(temp!=null) {             System.out.print(temp.val+" ");             temp=temp.next;         }     ...

Set / update the value in linked list in java.

■》 Code link-> click πŸ‘‡πŸ‘‡πŸ‘‡ https://www.programiz.com/online-compiler/8RZjEuY7ZCVC7 ■》 Program-> import java.util.Scanner; class Node{     int val;     Node next;     Node(int val){         this.val=val;     } } class Sll{     Node head;     Node tail;     int size;     void insertAtEnd(int val){     Node temp = new Node(val);     if(head==null) head=tail=temp;     else       {         tail.next=temp;         tail=temp;        }        size++;     }     void display(){         Node temp=head;         while(temp!=null) {             System.out.print(temp.val+" ");             temp=temp.next;         }       ...

Delete an element at the end of linked list in java.

■》Code link πŸ”— -> click πŸ‘‡πŸ‘‡πŸ‘‡ https://www.programiz.com/online-compiler/5XK4mKu63QU3u ■》Program-> class Node{     int val;     Node next;     Node(int val){         this.val=val;     } } class Sll{     Node head;     Node tail;     int size;     void insertAtEnd(int val){     Node temp = new Node(val);     if(head==null) head=tail=temp;     else       {         tail.next=temp;         tail=temp;        }        size++;     }     void display(){         Node temp=head;         while(temp!=null) {             System.out.print(temp.val+" ");             temp=temp.next;         }         System.out.println...

Delete an element from a given Index in linked list in java.

■》 Code linkπŸ”— -> clickπŸ‘‡πŸ‘‡πŸ‘‡ https://www.programiz.com/online-compiler/6fkgrxG1pyevE ■》Program->  class Node{     int val;     Node next;     Node(int val){         this.val=val;     } } class Sll{     Node head;     Node tail;     int size;     void insertAtEnd(int val){     Node temp = new Node(val);     if(head==null) head=tail=temp;     else       {         tail.next=temp;         tail=temp;        }        size++;     }     void display(){         Node temp=head;         while(temp!=null) {             System.out.print(temp.val+" ");             temp=temp.next;         }         System.out.pr...

Delete an element at the starting of linked list in java.

Code link πŸ”— -> click πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡ https://www.programiz.com/online-compiler/7xP5aBU4Orcx8 ■》Program-> class Node{     int val;     Node next;     Node(int val){         this.val=val;     } } class Sll{     Node head;     Node tail;     int size;     void insertAtEnd(int val){     Node temp = new Node(val);     if(head==null) head=tail=temp;     else       {         tail.next=temp;         tail=temp;        }        size++;     }     void display(){         Node temp=head;         while(temp!=null) {             System.out.print(temp.val+" ");             temp=temp.next;         }         System.out.println...

Get data / value of a node in linked list in java.

■》Code link-> click πŸ‘‡πŸ‘‡πŸ‘‡ https://www.programiz.com/online-compiler/0kNflMEyTAhkz ■》Program-> import java.util.Scanner; class Node{     int val;     Node next;     Node(int val){         this.val=val;     } } class Sll{     Node head;     Node tail;     int size;     void insertAtEnd(int val){     Node temp = new Node(val);     if(head==null) head=tail=temp;     else       {         tail.next=temp;         tail=temp;        }        size++;     }     void display(){         Node temp=head;         while(temp!=null) {             System.out.print(temp.val+" ");             temp=temp.next;         }       ...

Insert the element at given index in Linked list in java.

 class Node{     int val;     Node next;     Node(int val){         this.val=val;     } } class Sll{     Node head;     Node tail;     int size;     void insertAtIndex(int x,int val){         if(x==0){             Node temp = new Node(val);             head=temp;             size++;             return;         }         if(x<0 || x>size){          System.out.println("invalid index");          return;         }         if(x==size){             Node tail=head;             Node temp=new Node(val);             for(int i=1; i<...

Insert the element at Start in Linked List in java.

class Node{     int val;     Node next;     Node(int val){         this.val=val;     } } class Sll{     Node head;     Node tail;     int size;     void insertAtStart(int val){       Node temp = new Node(val);             if(head==null)          head=tail=temp;         else         {             temp.next=head;             head=temp;         }         size++;     }     void display(){         Node temp=head;         while(temp!=null) {             System.out.print(temp.val+" ");             temp=temp.next;         }       ...

Insert the element at end of Linked List in java.

program- > class Node{     int val;     Node next;     Node(int val){         this.val=val;     } } class Sll{     Node head;     Node tail;     int size;     void insertAtEnd(int val){     Node temp = new Node(val);     if(head==null) head=tail=temp;     else       {         tail.next=temp;         tail=temp;        }        size++;     }     void display(){         Node temp=head;         while(temp!=null) {             System.out.print(temp.val+" ");             temp=temp.next;         }         System.out.println();     }     void size(){         System.out.print...