Print circular linked list
package linkedlist_questions;
public class circularLinkedList {
public static class node {
node prev;
int data;
node next;
node(int data) {
this.data = data;
}
}
public static void printCll(node head){
System.out.print(head.data+" ");
head=head.next;
node temp=head;
while (temp.next!=head){
System.out.print(temp.data+" ");
temp=temp.next;
}
System.out.println();
}
public static void main(String[] args) {
node a=new node(4);
node b=new node(6);
node c=new node(8);
node d=new node(12);
a.prev=d;
a.next=b;
b.prev=a;
b.next=c;
c.prev=b;
c.next=d;
d.prev=c;
d.next=a;
printCll(a);
}
}
.png)
Comments
Post a Comment