QUEUES USING LINKED LISTS

import java.io.*; class node {             int n;             node prev,next; } class queuell {    public static void main...

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

Related

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, {-----...

Explain Tree Terminology ?

Tree : A Tree is a non linear data structure which organised elements in hierarchical representation.  That means trees data structure store data values in non contagious memory locations wit...

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