CIRCULAR QUEUES USING LINKED LISTS

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

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

Related

Java Program on Queues using Arrays

            class QueuesArrays { public static void main(String args[] )throws IOException { BufferedReader br=new BufferedReader (new InputStreamReader(Syste...

Java Program on Output Restricted DeQueue

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()); N...

Explain about Notations in Data Structures?

Evaluating expressions: let Q be an arithmetic expression involving both operator &operands. Operator: operator is a symbol that perform a particular tasks. High priority { 1 }, c, {-----...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item