forked from gumitrathore/DSA-Experiments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue_linkedlist.cpp
89 lines (88 loc) · 1.2 KB
/
queue_linkedlist.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
struct node
{
int info;
struct node* next;
};
typedef struct node queue;
queue *f=NULL;
queue *r=NULL;
void insert(int);
int delet();
void display();
int main()
{
int ch,item;
while(1)
{
cout<<"1.insert , 2.delet ,3.display , 4.exit "<<endl;
cout<<"enter your choice"<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"enter the item "<<endl;
cin>>item;
insert(item);
break;
case 2:
cout<<"deleted item is "<<delet()<<endl;
break;
case 3:
display();
break;
case 4:
exit(0);
break;
default :
cout<<"please enter valid choice"<<endl;
}
}
getch();
return 0;
}
void insert(int item)
{
queue* n;
n=(queue*)malloc(sizeof(queue));
n->info=item;
n->next=NULL;
if(f==NULL)
{
f=n;
r=n;
}
else
{
r->next=n;
r=n;
}
}
int delet()
{
int x;
queue* n;
if(f==NULL)
{
cout<<"queue underflow"<<endl;
return 0;
}
else
{
n=f;
f=n->next;
x=n->info;
free(n);
return x;
}
}
void display()
{
queue* i;
cout<<"queue is"<<endl;
for(i=f;i!=NULL;i=i->next)
cout<<i->info<<endl;
}