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