circular doubly linked list deletion at begining

 first node delete circular doubly linked list

public class cdll {
class Node {
int data;
Node prev;
Node next;

Node(int data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
Node head=null;
Node tail=null;
public void toadd(int data){
Node newnode=new Node(data);
if (head==null){
head=newnode;
tail=newnode;
newnode.next=head;
newnode.prev=tail;
}
else{
tail.next=newnode;
newnode.prev=tail;
tail=newnode;
tail.next=head;
head.prev=tail;
}
}

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 delbeg(){
Node temp=head;
temp=temp.next;
head=temp;
head.prev=tail;
tail.next=head;
    }
public static void main(String[] args) {
cdll cc=new cdll();
cc.toadd(10);
cc.toadd(20);
cc.toadd(45);
cc.toadd(70);
cc.dis();
System.out.println("*************");
        cc.delbeg();
        cc.dis();
}
}

Comments

Popular posts from this blog

Back / Flip Cover Universal List

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