-
Notifications
You must be signed in to change notification settings - Fork 2
/
9.queue
152 lines (136 loc) · 2.19 KB
/
9.queue
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//IMP
//queue empty:- (head=null)
//deq is to delete element from front
//enq is to insert element from back
//Make a singly linked list by class node and class ll
//Make data memebers private and use friend class ll; in node class.
//In class ll, have only head
//
//Member fns:
//void ins(int n);
//void del();
//void disp();
//bool isempty();
//create node* nn=new node;
//nn->prn=n;
//nn->next=NULL; in insert fn
//in insert:
//1. check if empty, if yes just do head=nn;
//2. if not, have while loop to reach end of list n then insert.
//in delete:
//1.check if empty, display del not possible
//2. if not, delete.
#include<iostream>
using namespace std;
class node
{
int prn;
node* next;
public:
node()
{
prn = 0;
}
friend class ll;
};
class ll
{
node* head;
public:
ll()
{
head = NULL;
}
void ins(int n);
void del();
void disp();
bool isempty();
};
bool ll::isempty()
{
if (head == NULL)
return true;
return false;
}
void ll::ins(int n)
{
node* nn = new node;
nn->prn = n;
nn->next = NULL;
if (isempty())
{
head = nn;
}
else
{
node* p = head;
while (p->next != NULL)
{
p = p->next;
}
p->next = nn;
}
cout << "---Inserted in Queue---" << endl;
}
void ll::del()
{
if (isempty())
cout << "---Nothing to delete--" << endl;
else
{
node* p = head;
head = head->next;
delete(p);
cout << "---Deleted from Queue---" << endl;
}
}
void ll::disp()
{
if (isempty())
cout << "---Nothing to Display---" << endl;
else
{
node* start = head;
while (start != NULL)
{
cout << start->prn << endl;
start = start->next;
}
}
}
int main()
{
int ch;
int ele;
ll a;
do
{
cout << "\n\t Enter ur Choice" << endl;
cout << "\n\t 1.Add Job" << endl;
cout << "\n\t 2.Delete Job" << endl;
cout << "\n\t 3.Display " << endl;
cout << "\n\t 4.Exit" << endl;
cin >> ch;
switch (ch)
{
case 1:
cout << "Enter PRN of Job" << endl;
cin >> ele;
a.ins(ele);
break;
case 2:
a.del();
break;
case 3:
cout << "---Displaying Queue---" << endl;
a.disp();
break;
case 4:
cout << "\n\tThank You!!!" << endl;
break;
default:cout << "Invalid Choice" << endl;
}
} while (ch != 4);
cout << "\n\tExit" << endl;
return 0;
}