-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprogram to implement Simple Queue using Class .cpp
84 lines (72 loc) · 1.61 KB
/
program to implement Simple Queue using Class .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
/* C++ program to implement Simple Queue using Class */
#include <iostream>
using namespace std;
class queue
{
private :
int *arr ;
int front, rear ;
int MAX ;
public :
queue( int maxsize = 10 ) ;
void addq ( int item ) ;
int delq( ) ;
} ;
queue :: queue( int maxsize )
{
MAX = maxsize ;
arr = new int [ MAX ];
front = -1 ;
rear = -1 ;
}
void queue :: addq ( int item )
{
if ( rear == MAX - 1 )
{
cout << "\nQueue is full" ;
return ;
}
rear++ ;
arr[rear] = item ;
if ( front == -1 )
front = 0 ;
}
int queue :: delq( )
{
int data ;
if ( front == -1 )
{
cout << "\nQueue is Empty" ;
return NULL ;
}
data = arr[front] ;
arr[front] = 0 ;
if ( front == rear )
front = rear = -1 ;
else
front++ ;
return data ;
}
int main( )
{
queue a (10 ) ;
a.addq ( 23 ) ;
a.addq ( 9 ) ;
a.addq ( 11 ) ;
a.addq ( -10 ) ;
a.addq ( 25 ) ;
a.addq ( 16 ) ;
a.addq ( 17 ) ;
a.addq ( 22 ) ;
a.addq ( 19 ) ;
a.addq ( 30 ) ;
a.addq ( 32 ) ;
int i = a.delq( ) ;
cout << "\n\nItem deleted: " << i ;
i = a.delq( ) ;
cout << "\n\nItem deleted: " << i ;
i = a.delq( ) ;
cout << "\n\nItem deleted: " << i ;
cout<<"\n";
return 0;
}