reversing stacks

I don't understand where my coding is wrong. These are the errors I am getting when I debug: Error 2 error LNK2019: unresolved external symbol "public: bool __thiscall linkedStackType<int>::operator==(class linkedStackType<int> const &)" (??8?$linkedStackType@H@@QAE_NABV0@@Z) referenced in function _main E:\Chapter7a\Chapter7a\Chapter7a\Chapter7a.obj Chapter7a
Warning 1 warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:LBR' specification E:\Chapter7a\Chapter7a\Chapter7a\Chapter7a.obj Chapter7a


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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
  //Header File: linkedStack.h

#ifndef H_StackType
#define H_StackType

#include <iostream>
#include <cassert>

#include "stackADT.h"

using namespace std;


//Definition of the node
template <class Type>
struct nodeType
{
	Type info;
	nodeType<Type> *link;
};

template <class Type>
class linkedStackType : public stackADT<Type>
{
public:
	const linkedStackType<Type>& operator=
		(const linkedStackType<Type>&);
	bool operator==(const linkedStackType<Type>&);

	bool isEmptyStack() const;


	bool isFullStack() const;

	void initializeStack();

	void push(const Type& newItem);

	Type top() const;

	void pop();

	linkedStackType();

	linkedStackType(const linkedStackType<Type>& otherStack);

	~linkedStackType();

	void reverseStack(linkedStackType<Type> &);


private:
	nodeType<Type> *stackTop; //pointer to the stack

	void copyStack(const linkedStackType<Type>& otherStack);

};

//Default constructor
template <class Type>
linkedStackType<Type>::linkedStackType()
{
	stackTop = NULL;
}

template <class Type>
bool linkedStackType<Type>::isEmptyStack() const
{
	return(stackTop == NULL);
} //end isEmptyStack

template <class Type>
bool linkedStackType<Type>::isFullStack() const
{
	return false;
} //end isFullStack

template <class Type>
void linkedStackType<Type>::initializeStack()
{
	nodeType<Type> *temp; //pointer to delete the node

	while (stackTop != NULL)  //while there are elements in 
		//the stack
	{
		temp = stackTop;    //set temp to point to the 
		//current node
		stackTop = stackTop->link;  //advance stackTop to the
		//next node
		delete temp;    //deallocate memory occupied by temp
	}
} //end initializeStack


template <class Type>
void linkedStackType<Type>::push(const Type& newElement)
{
	nodeType<Type> *newNode;  //pointer to create the new node

	newNode = new nodeType<Type>; //create the node

	newNode->info = newElement; //store newElement in the node
	newNode->link = stackTop; //insert newNode before stackTop
	stackTop = newNode;       //set stackTop to point to the 
	//top node
} //end push


template <class Type>
Type linkedStackType<Type>::top() const
{
	assert(stackTop != NULL); //if stack is empty,
	//terminate the program
	return stackTop->info;    //return the top element 
}//end top

template <class Type>
void linkedStackType<Type>::pop()
{
	nodeType<Type> *temp;   //pointer to deallocate memory

	if (stackTop != NULL)
	{
		temp = stackTop;  //set temp to point to the top node

		stackTop = stackTop->link;  //advance stackTop to the 
		//next node
		delete temp;    //delete the top node
	}
	else
		cout << "Cannot remove from an empty stack." << endl;
}//end pop

template <class Type>
void linkedStackType<Type>::copyStack
(const linkedStackType<Type>& otherStack)
{
	nodeType<Type> *newNode, *current, *last;

	if (stackTop != NULL) //if stack is nonempty, make it empty
		initializeStack();

	if (otherStack.stackTop == NULL)
		stackTop = NULL;
	else
	{
		current = otherStack.stackTop;  //set current to point
		//to the stack to be copied

		//copy the stackTop element of the stack 
		stackTop = new nodeType<Type>;  //create the node

		stackTop->info = current->info; //copy the info
		stackTop->link = NULL;  //set the link field of the
		//node to NULL
		last = stackTop;        //set last to point to the node
		current = current->link;    //set current to point to
		//the next node

		//copy the remaining stack
		while (current != NULL)
		{
			newNode = new nodeType<Type>;

			newNode->info = current->info;
			newNode->link = NULL;
			last->link = newNode;
			last = newNode;
			current = current->link;
		}//end while
	}//end else
} //end copyStack

//copy constructor
template <class Type>
linkedStackType<Type>::linkedStackType(
	const linkedStackType<Type>& otherStack)
{
	stackTop = NULL;
	copyStack(otherStack);
}//end copy constructor

//destructor
template <class Type>
linkedStackType<Type>::~linkedStackType()
{
	initializeStack();
}//end destructor

//overloading the assignment operator
template <class Type>
const linkedStackType<Type>& linkedStackType<Type>::operator=
(const linkedStackType<Type>& otherStack)
{
	if (this != &otherStack) //avoid self-copy
		copyStack(otherStack);

	return *this;
}//end operator=

template <class Type>
void linkedStackType<Type>::reverseStack(linkedStackType<Type>& right)
{
	right.initializeStack();
	nodeType<Type> *temp = this->stackTop;
	while (temp != NULL)
	{	
		right.push(temp->info);
	temp = temp->link;
}
}
#endif

#include "stdafx.h"
#include "linkedStack.h"
using namespace std;


int main()
{
	cout << "This program reverses elements of a stack onto another stack" << endl;
	linkedStackType<int> stack1;
	linkedStackType<int> stack2;

	cout << "Inserting elements 5, 10, and 15 into both the stacks" << endl;

	for
		(int i = 5; i < 50; i += 5)
		stack1.push(i);

	stack2 = stack1;
	//check for equality of the stacks
	if
		(stack1 == stack2)
		cout << "The two stacks are equal";
	else
		cout << "The tow stacks are unequal";

	//reverse the stack on to another stack
	cout << "Reversing the stack onto another stack";
	stack1.reverseStack(stack2);

	//check for equality of the stacks
	if
		(stack1 == stack2)
		cout << "The two stacks are equal";
	else
		cout << "The tow stacks are unequal";

	//pritn the elements of the stack 1
	cout << "The elements in the first stack are: ";
	while (!stack1.isEmptyStack())
	{
		cout << stack1.top() << " ";
		stack1.pop();
	}

	//print the elements of stack2
	cout << "The elements in the second stack are: ";
	while (!stack2.isEmptyStack())
	{
		cout << stack2.top() << " ";
		stack2.pop();
	}
	system("PAUSE");
	return 0;
You have given the prototype for operator==, but you never define it.

I'm actually not sure how to compare stacks, as one of their properties is that only the top element is visible.
Topic archived. No new replies allowed.