sign up I login
 advanced
refer a friend - earn nickels!!

Ask & Discuss Questions with Community & Experts

Moderation Team
Ask iit jee aieee pet cbse icse state board community Discussion Response Post to: stacks and queue
Forum Index -> Computer Science -> View Full Question like the article? email it to a friend.  
Author Message
sugargal_anu (169)

Hot goIITian

Olaaa!! Perrrfect answer. 31  [38 rates]

sugargal_anu's Avatar

total posts: 135    
offline Offline
//queue as linked list
#include<iostream.h>
#include<process.h>
#include<conio.h>
struct queue
{
    int no;
    char name[20];
    queue *link;
    void accept()
    {
        cout<<"Enter no. & name ";
        cin>>no>>name;
    }
    void output()
    {
        cout<<no<<" "<<name<<endl;
    }
};
void qinsert(queue *&front,queue *&rear)
{
    queue *temp;
    temp=new queue;
    temp->accept();
    temp->link=NULL;
    if(rear==NULL)
        front=rear=temp;
    else
    {
        rear->link=temp;
        rear=temp;
    }
}
void qdelete(queue *&front)
{
    if(front==NULL)
        cout<<"\nUnderflow\n";
    else
    {
        queue *temp;
        temp=new queue;
        temp=front;
        temp->output();
        front=front->link;
        delete temp;
    }
}
void qdisplay(queue *front,queue *rear)
{
    if(front==rear)
        cout<<"\nQueue is empty\n";
    else
        while(front)
        {
            front->output();
            front=front->link;
        }
}
void main()
{
    clrscr();
    queue *front, *rear;
    front=new queue;
    front=NULL;
    rear=new queue;
    rear=NULL;
    int op;
    char ch;
    do
    {
        cout<<"\n1.Insert\n2.Delete\n3.Display\n4.Exit\n";
        cout<<"Enter your choice ";
        cin>>op;
        if(op==1)
            qinsert(front,rear);
        if(op==2)
            qdelete(front);
        if(op==3)
            qdisplay(front,rear);
        if(op==4)
            exit(0);
        cout<<"\nWant to continue? ";
        cin>>ch;
    }while(ch=='y'||ch=='Y');
}

Orkut Graphics - Angels
 this reply: 2 points  (with Olaaa!! Perrrfect answer.   in 1 votes )   [?]
 
You have to be logged on to rate
  
 

Top Offers for goIITians
Correspondence Courses
Brilliant Tutorials
Narayana Institute
Aakash Institute
Classroom/Crash Courses
Narayana - Kota , Delhi , Others
Brilliant Tutorials - Class , Crash
Aakash Institute - Medical , Engg
Online Test Series
Brilliant Tutorials
Narayana Institute
Aakash Institute
Mahesh Tutorials
AMITY      Sri Chaitanya