Java Program on Output Restricted DeQueue

class Node { int n; Node prev,next; } class ORD { public static void main(String args[ ])throws IOException { Buffered...


class Node
{
int n;
Node prev,next;
}
class ORD
{
public static void main(String args[ ])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader (System.in());
Node front=null, rear=null,p;
int ch , op;
do
{
System.out.println(“1.insertion\n 2: deletion\n3;display);
System.out.println(“enter ur choice”);
op= Integer.parseInt(br.readLine( ) );
p= new node();
System.out.println(“enter data”);
p.n= Integer.parseInt (br.readLine( ) );
switch(op)
{
case 1:
if(front==null)
{
front=p;
rear=p;
}
else
{
rear.next=p;
p.prev=rear;
rear=p;
rear.next=null;
}
break;
case 2:
if(front==null)
{
front=p;
rear=p;
}
else
{
front . prev=p;
p.next=front;
front=p;
front.prev=null;
}
}
break;
}
break;
case 2:
if(front==null)
{
  System.out.println(“Queue is empty”);
}
else
{
System.out.println(front.n+”deleted”);
front=front.next;
front.prev=null;
}
}
break;
case 3:
if(front ==null)
{
System.out.println(“Queue is empty”);
}
else
{
for(p=front;p!=null;p=p.next)
{
 System.out.println(p.n);
}
}
break;
}
}while( ch < 4 );
}
}



Related

Data Structures 2156691297263211448

Post a Comment

emo-but-icon

item