forked from ambujraj/hacktoberfest2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LLqueues.cpp
118 lines (116 loc) · 1.83 KB
/
LLqueues.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// MANCHESTER UNITED >>>>> BARCELONA
#include <iostream>
using namespace std;
class node
{
int info;
node* next;
public:
node* enqueue(node*);
node* deque(node*);
node* display(node*);
};
node* node::enqueue(node* start)
{
node* temp;
cout<<"enqueue...\n";
if(start==NULL)
{
cout<<"Queue was empty..Entering first element..\n";
temp = new node;
cout<<"Enter info..\n";
cin>>temp->info;
temp->next = NULL;
start = temp;
temp = NULL;
}
else
{
node* temp1;
temp = start;
while(temp->next)
{
temp = temp -> next;
}
temp1 = new node;
temp1 -> next = NULL;
cout<<"Enter information..\n";
cin>>temp1->info;
temp -> next = temp1;
temp=temp1=NULL;
}
return start;
}
node* node::deque(node* start)
{
node* temp;
cout<<"Deleting..\n";
if(start==NULL)
{
cout<<"Queue empty..\n";
return start;
}
else if(start->next == NULL)
{
cout<<"Single element present..\n";
cout<<"Data deleted is.."<<start->info<<"\n";
delete start;
start = NULL;
return start;
}
else
{
temp = start;
start = start -> next;
cout<<"Element deleted is.."<<temp->info<<" "<<"\n";
delete temp;
return start;
}
}
node* node::display(node* start)
{
node* temp;
if(start==NULL)
{
cout<<"Queue empty..\n";
return start;
}
else
{
temp = start;
while(temp)
{
cout<<" "<<temp->info<<" ";
temp = temp -> next;
}
cout<<"\n";
temp = NULL;
return start;
}
}
int main()
{
node* start = NULL;
node n;
int ch=1,ch1;
while(ch)
{
cout<<"\n\nEnter 1.enqueue\n\t2.dequeue\n\t3.display\n\t4.Exit\n\n";
cin>>ch1;
switch(ch1)
{
case 1: cout<<"enqueue..\n";
start = n.enqueue(start);
break;
case 2: cout<<"deque..\n";
start = n.deque(start);
break;
case 3: cout<<"Displaying..\n";
start = n.display(start);
break;
case 4: cout<<"Exit..\n";
ch=0;
break;
}
}
}