-
Notifications
You must be signed in to change notification settings - Fork 0
/
queueSLL.cpp
97 lines (91 loc) · 1.25 KB
/
queueSLL.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
#include <stdio.h>
#include <conio.h>
#include <iostream>
using namespace std;
struct node
{
int item;
node *next;
};
class queue
{
private:
node *rear;
node *front;
public:
queue();
void inserting(int);
bool isEmpty();
int getRear();
int getFront();
void deleting();
int count();
~queue();
};
int queue::count(){
node *ptr;
int c=0;
while(ptr){
c++;
ptr=ptr->next;
}
return c;
}
queue::~queue(){
while(front==NULL)
deleting();
}
void queue::deleting()
{
node *ptr;
ptr = front;
if(!isEmpty()){
ptr=front;
front=front->next;
if(front==NULL)
rear=NULL;
delete ptr;
}
}
int queue::getFront()
{
if (isEmpty())
return -1;
return front->item;
}
int queue::getRear()
{
if (isEmpty())
return -1;
return rear->item;
}
queue::queue()
{
front = NULL;
rear = NULL;
}
bool queue::isEmpty()
{
return rear == NULL;
}
void queue::inserting(int data)
{
node *n;
n = new node;
n->item = data;
if (isEmpty())
{
rear = n;
front = n;
}
else
{
rear->next = n;
rear = n;
rear->next = NULL;
}
}
int main()
{
return 0;
}