Created
February 10, 2014 18:13
-
-
Save xXFracXx/8921198 to your computer and use it in GitHub Desktop.
B) Queues [Linked List]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Queue using linked list | |
#include<iostream.h> | |
#include<stdlib.h> | |
#include<stdio.h> | |
#include<conio.h> | |
#include<ctype.h> | |
struct node | |
{ | |
char name[20]; | |
int age; | |
int sal; | |
node *link; | |
}; | |
class queue | |
{ | |
node *top; | |
node *rear; | |
public: | |
queue() | |
{ | |
top=NULL; | |
}; | |
void queuepush(); | |
void queuepop(); | |
void queueshow(); | |
}obj; | |
void queue::queuepush() | |
{ | |
node *temp; | |
temp= new node; | |
cout<<"employee name enter :\t"; | |
cin>>temp->name; | |
cout<<"employee enter no\t"; | |
cin>>temp->age; | |
cout<<"enter employee slary"; | |
cin>>temp->sal; | |
temp->link=NULL; | |
if(top==NULL) | |
top=rear=temp; | |
else | |
{ | |
rear->link=temp; | |
rear=temp; | |
} | |
} | |
void queue::queuepop() | |
{ | |
int val; | |
node *temp; | |
if(top==NULL) | |
{ | |
cout<<"stack empty "; | |
val=-1; | |
} | |
else | |
{ | |
temp=top; | |
top=top->link; | |
temp->link=NULL; | |
delete temp; | |
} | |
} | |
void queue::queueshow() | |
{ | |
node *temp; | |
temp=top; | |
cout<<"the values are"; | |
while(temp!=NULL) | |
{ | |
cout<<"\n"<<temp->age; | |
cout<<"\n"<<temp->name; | |
cout<<"\n"<<temp->sal; | |
temp=temp->link; | |
} | |
} | |
int main() | |
{ | |
queue s; | |
int ch=2; | |
cout<<"\nPress 1 For Push \nPress 2 For Pop \nPress 3 For Display \nPress 4 To Exit\n\n"; | |
while(ch) | |
{ | |
cout<<"Choose an Option"; | |
cin>>ch; | |
switch (ch) | |
{ | |
case 2: | |
s.queuepop(); | |
break; | |
case 1: | |
s.queuepush(); | |
break; | |
case 3: | |
s.queueshow(); | |
break; | |
case 4: exit(0); | |
default :cout<<"...\n\n\n"; | |
} | |
} | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment