circular linked list insertion at the end

 singly circular linked list insertion at last position

import java.util.Scanner;

public class cll {
class Node{
int data;
Node next;
Node(int data){
this.data=data;
this.next=null;
}

}
Node head=null;
Node tail=null;
public void toadd(int data){
Node newnode=new Node(data);
if (head==null){
head=newnode;
tail=newnode;
tail.next=head;
}
else{
tail.next=newnode;
tail=newnode;
tail.next=head;
}
}
public void dis(){
Node temp=head;
if (head==null){
System.out.println("empty");
}
else{
do {
System.out.println(temp.data);
temp=temp.next;
}while (temp!=head);
}
}
    public void addlast(int daatas){
Node newnode=new Node(daatas);
tail.next=newnode;
tail=newnode;
newnode.next=head;

    }
public static void main(String[] args) {
cll cc=new cll();
cc.toadd(10);
cc.toadd(20);
cc.toadd(30);
cc.toadd(40);
cc.dis();
System.out.println("*******");
    cc.addlast(55);
    cc.dis();
}
}

Comments

Popular posts from this blog

Back / Flip Cover Universal List

Super-D, 11D, Super X tempered glass Universal list