CIRCULAR QUEUES USING LINKED LISTS
import java.io.*; class node { int n; node prev,next; } class cqueue { public static void main(String args[])throws...

https://www.computersprofessor.com/2016/06/circular-queues-using-linked-lists.html
import java.io.*;
class node
{
int n;
node prev,next;
}
class cqueue
{
public static void
main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
node
p,q,front=null,rear=null;
int
ch,count=0;
do
{
System.out.println("1:insertion\n2:deletion\n3:display");
System.out.println("enter
u r choice");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
p=new
node();
System.out.println("enter
data");
p.n=Integer.parseInt(br.readLine());
if(front==null)
{
front=p;
rear=p;
}
else
{
rear.next=p;
p.prev=rear;
rear=p;
rear.next=front;
front.prev=rear;
}
front.prev=rear;
rear.next=front;
count++;
break;
case 2:
p=front;
System.out.println("element"+p.n+"deleted");
front=front.next;
front.prev=rear;
rear.next=front;
count--;
break;
case 3:
System.out.println("1:forwardtraversol\n2:backwardtraversol");
System.out.println("enter
u r choice");
int
op=Integer.parseInt(br.readLine());
switch(op)
{
case
1:
int co=count;
p=front;
while(co >= 1)
{
System.out.println(p.n);
co--;
p=p.next;
}
break;
case
2:
co=count;
p=rear;
while(co>=1)
{
System.out.println(p.n);
co--;
p=p.prev;
}
break;
}
}
}while(ch!=4);
}
}
OUTPUT:
1:insertion
2:deletion
3:display
enter u r choice
1
enter data
10
1:insertion
2:deletion
3:display
enter u r choice
1
enter data
20
1:insertion
2:deletion
3:display
enter u r choice
3
1:forwardtraversol
2:backwardtraversol
enter u r choice
1
10
20
1:insertion
2:deletion
3:display
enter u r choice
4