请帮我一把。我收到上述错误消息,但尚未能够解决它。我在这里粘贴了头文件和commonStack函数。也许你会看到我错过的东西。我也收到“未终止的ifndef”错误消息。正如你从头文件中看到的那样,我用endif结束了这个类。所以我不确定我做错了什么。请帮忙。谢谢。变量或字段'commonStack'声明为空
//Header file.
//Class definition for the stack ADT
#ifndef _mystack_H
#include <ostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define _mystack_H
const unsigned int maxSize = 10;
class Stack
{
public:
Stack(); //constructor
~Stack(); //Destructor
bool isEmptyStack();
bool isFullStack();
void pushStack(int newItem);
void popStack(int item);
void initializeStack();
void fillStack(int numSize);
void exchangeTopAndBottom(Stack &stk);
void printStack(Stack &stk);
int sumStack(Stack &stk);
void OddElem(Stack &stk);
//void commonStack(Stack &stk1, Stack &stk2);
void intersectStack(Stack &stk1, Stack &stk2);
private:
int maxSize; //variable to store the maximum stack size
int stackTop; //variable to poit to the top of the stack
Stack arrList;//pointer to the array that holds the stack
//elements
};
#endif
//commonStack finds the union of two stacks
void Stack::commonStack(Stack &stk1, Stack &stk2)
{
Stack temp, temp2, tempStk, tempStk1, tempStk2, cStack;
int elem, elem1, elem2, elem3;
while (!stk1.isEmptyStack())
{
stk1.popStack(elem);
cStack.pushStack(elem);
tempStk1.pushStack(elem);
}
while (!stk2.isEmptyStack())
{
stk2.popStack(elem1);
while (!tempStk1.isEmptyStack())
{
tempStk1.popStack(elem2);
if (elem1 == elem2)
{
temp.pushStack(elem2);
tempStk2.pushStack(elem2);
}
else
{
temp2.pushStack(elem2);
tempStk2.pushStack(elem2);
}
}
while (!tempStk2.isEmptyStack())
{
tempStk2.popStack(elem2);
tempStk1.pushStack(elem);
}
tempStk.pushStack(elem1);
}
while (!cStack.isEmptyStack())
{
temp2.popStack(elem3);
cStack.pushStack(elem3);
}
printStack(cStack);
}
'commonStack'被注释掉,并且在您发布的代码中没有'#endif'。 – curiousguy
@curiousguy:是的,只是不在文件的末尾。 –
我看到'#endif'。但是'commonStack'的声明在哪里? – curiousguy