stackTop

I am trying to implement this stackTop function into my program, but I am having a hard time trying to understand why it does not display the member information. The function works but I don't understand why no member information is displayed.

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
struct stackNode{
	char vehicleType;
	string license;
	int vehicleCapacity;
	stackNode *next;
};

struct stackMeta{
	int count;
	stackNode *head;
};

  bool StackTop(stackMeta *stackHead)
{
	//local variables
	bool success;
	//stackNode *head;
	char vehicleT;
	string vehicleLicense;
	int vehicleCapacity;

//	dataTop = new stackNode;

	if(!IsEmptyStack(stackHead))
	{
		success = false;
	}
	else
	{
		vehicleT = stackHead->head->vehicleType;
		vehicleLicense = stackHead->head->license;
		vehicleCapacity = stackHead->head->vehicleCapacity;
		
		success = true;
	}
        //This is a test cout. It displays the address of the top
        //node but it does not display the data in the members.
	cout << "Yes " << stackHead->head << vehicleT << endl;
	return success;
}
Last edited on
guesses:
- It works perfectly, but because you didn't put an space between the outputs you are confusing `vehicleT' with part of the address.
- `vehicleT' does not contain a printable character
- The stack is not empty so the condition in line 24 is true, `vehicleT' is uninitialized.
Thank you so much. I needed an extra set of eyes. I've been staring at this code for a long time. The funny thing is that I had the same problem with a different function. I changed the if test and forgot to remove the !.
Topic archived. No new replies allowed.