deque class having problems in inserting dATA INTO THE QUEUE

HI ALL
i am having problem in inserting data into the queue....will some one help me to fix it ?
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// deque assng2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

template<class type>
class deque
{
	type front,rear;
	type MAX;
	type* items;
public:
	deque(int max)
	{
		front=-1;rear=-1;
		MAX=max;
		items=new type[max];
	}
	void insertfront(type a)
	{
		if(isempty())
		{
				front=0;rear=0;
				items[front]=a;
		}
		else if(isfull())
			cout<<"Over flow\n";
		else if(front==MAX-1)
		{
			front=0;
		}
		else
		{
			items[front]=a;
		}
	}

	void insertrear(type a)
	{
		if(isempty())
		{
				front=0;rear=0;
				//items[rear]=a;
		}
		else if(isfull())
			cout<<"Over flow\n";
		else if(rear==0)
		{
			//items[rear]=a;
			rear=MAX-1;
		}
		else
		{
			rear=rear-1;
			items[rear]=a;
			
		}
	}

	void removefront(type &a)
	{
		if(isempty())
			cout<<"under flow \n";
		else if(front==rear)
		{
			a=items[front];
			front=-1;rear=-1;
		}
		else
		{
			if(front==MAX-1)
			{
				a=items[front];
				front=0;
			}
			else 
				front=(front+1);
		}
	}
	void removerear(type &a)
	{
		if(isempty())
		cout<<"under flow \n";
		else if(rear==front)
		{
			a=items[rear];
			rear=-1;front=-1;
		}
		else
		{
			if(rear==0)
			{
				a=items[rear];
				rear=MAX-1;
			}
			else
				rear=(rear+1)%MAX;
		}
	}
	//type first();
	//type last();
	bool isempty()
	{
		if(front==-1 && rear==-1)
		{
			cout<<"the queue is empty \n";			
			return true;
		}
		else return false;
	}
	bool isfull()
	{
		if(front==0 && rear==MAX-1 || front==rear+1)
		{
			cout<<"the queue is full \n";
			return true;
		}
		else return false;
	}
	void print_que()
	{
		int a=front;
		int b=right;
		if(isempty()){exit(1);}
		if(a<=b)
		{
			while(a<=b)
			{
				cout<<items[a];
				a++;
			}
		}
		else
		{
			while(a<=MAX-1)
			{
				cout<<items[a];
				a++;
			}
			a=0;
			while(a<=b)
			{
				cout<<items[a];
				a++;
			}
		}
	}

};

int main()
{
	int dequeSize;
	cout<<"enter the size of the Queue\n";
	cin>>dequeSize;
	deque<int> D(dequeSize);
	D.insertfront(10);
	D.insertfront(20);
	D.insertfront(30);
	int a;
	D.removefront(a);
	cout<<a<<endl;
	D.removefront(a);
	cout<<a<<endl;
	D.removefront(a);
	cout<<a<<endl;
	int b;
	D.insertrear(1);
	D.insertrear(2);
	D.insertrear(3);
	cout<<"insertion from rear"<<endl;
	D.removerear(b);
	cout<<b<<endl;
	D.removerear(b);
	cout<<b<<endl;
	D.removerear(b);
	cout<<b<<endl;
	
	system("pause");
	return 0;
}
Topic archived. No new replies allowed.