請幫我一把。我收到上述錯誤消息,但尚未能夠解決它。我在這裏粘貼了頭文件和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