bool Stack::Empty() function not working?

Hello,

I am currently implementing a class Stack Linked List and my Empty function seems to be unable to return a true value when the Stack has no Nodes and causes my program to have an error and shut down. Here is my Empty function:

1
2
3
4
5
6
7
  bool Stack::Empty()
{
	if(Top==0)
		return true;
	else
		return false;
}


This is where I am using my Empty function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
bool Stack::Pop(Coordinate& coordinate)
{
	if(Stack::Empty()==true)
		return false;
	
	coordinate = Top->data;
	Node * Temp = Top;
	Top = Top->next;

	
	delete Temp;
	
	return true;
	
}


I've tried various things, but none of them seem to work. I am writing this on Microsoft Visual Studio. Any advice would be greatly appreciated!
Last edited on
Please post the definition of Stack.
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
typedef struct{int row; int column;} Coordinate;


struct Node
{
	Coordinate data;
	Node * next;
};


class Stack
{
public:
	
	Stack();

	
	~Stack();

	
	bool Empty();

	
	bool Push(Coordinate);

	
	bool Pop(Coordinate&);

private:

	Node * Top;
};

 
It looks OK to me. Could you post a small example of making an empty stack then trying to pop off of it that fails as you describe? I'd also recommend using a debugger to step through the program and see what is happening as it executes.
Topic archived. No new replies allowed.