Stack Problem

I am having a problem using stacks for my C++ program.

Here is what I have so far:

Stack.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
#include "stack.h"
 
namespace Stack
{
	const int max_size = 200;

	struct Rep 
	{
	 char v[max_size];
	 int top;
	};

	const int max = 16;

	Rep stacks[max];
	bool used[max];

	typedef Rep& stack;

}

 
void Stack::push(stack s, char c))
{
 if(s == max_size)
 throw Overflow();
 
 v[s] = c;
 s++;
 
 return;
}
 
char Stack::pop(char s)
{
 if(s < 0)
 throw Underflow();
 
 s--;
 
 return v[s];
}

Stack::stack s3 Stack::create()
{
	struct Rep1;
	typedef Rep1& stack;

	//pick an unused Rep, mark it used, initialize it, and return a reference to it
}

void Stack::destroy(stack s) 
{
	//Mark s unused
}


Stack.h
1
2
3
4
5
6
7
8
9
10
11
12
13
namespace Stack
{

 Struct Rep;
 typedef Rep& stack;

 stack create();
 void destroy(stack s);

 void push(stack s, char c);
 char pop(stack s);

}



The four bottom functions of the .cpp file are what I have to fill in, I don't know if my push/pop functions are correct, I am supposed to check s for overflow and push c in the first function, and check s for underflow and pop for the second function.

Now the bottom two functions, the create and destroy, I have what I need to do in the comments in them. I don't know what marking used and unused means and this book is absolutely no help at all.

It is basically parts of a program all mixed up between paragraphs, and we are supposed to recreate the whole program.

Any help?

Thank you in advance.

Last edited on
Stack is a class, not merely a namespace. Replace namespace with stack. They're two distinctly different things.
yes i agree with kbw .. and you cannot use array of v the way you have used it .
you have to declered it first .
Topic archived. No new replies allowed.