Whats wrong?

Show how to implement the main queue functions Enque() and Deque() using two stacks S1 & S2

You allowed only to call push () and pop() functions of the two stacks to implement Enque()and Deque() functions.

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
#include<iostream>
using namespace std;
const int size=5;
int arr[size];
int front=-1,rear=-1;
bool isfull()
{
	if(rear==size-1)
		return true;
	else 
		return false;
}
bool isempty()
{
	if(front==-1 || front>rear)
		return true;
	else 
		return false;
}
void enqueue (int item)
{
	if(isfull())
		cout<<"Queue is full\n";
	else 
	{
		rear++;
		arr[rear]=item;
		if(front==-1)
			front=0;
	}
}
int dequeue()
{
	int x;
	if(isempty())
		cout<<"queue is empty\n";
	else
	{
		x=arr[front];
		front++;
	}
	return x;
}
void main()
{
	s1.push(10);
	s2.push(20);
	int y=pop();
	cout<<"this item is removed: "<<y<<endl;
	for(int i=top;i>=0;i--)
		cout<<arr[i]<<endl;
	system("pause");
}
If I run the code from the forum, the compiler puts out these errors with the main function. At least in the code posted here, some things used in main have not been declared anywhere.

44:11: error: '::main' must return 'int' 
In function 'int main()': 
46:2: error: 's1' was not declared in this scope 
47:2: error: 's2' was not declared in this scope 
48:12: error: 'pop' was not declared in this scope 
50:12: error: 'top' was not declared in this scope 
but as the problem is demanding i need to have the s1 s2 thingy, how i declare them while still using the Queue functions?
Are you supposed to be building your own stack class with pop() and push() functions that call these queue functions you have in the code above? And s1 and s2 are stack objects you then declare in the main function?
nope actually the code is just a try of mine (which failed)
the problem doesn't include a code, its all on me
Last edited on
Topic archived. No new replies allowed.