这是我的功能,
template <class KeyType >
KeyType * Stack<KeyType>::Pop(KeyType& x) {
if (IsEmpty()) { //isempty is just a bool function
StackEmpty(); //just prints out that stack is empty
return 0; //bad coding breaking out of the function
}
x = stack[top--]; //stack is a pointer to an array, top is the top of the stack
return &x;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:我不确定这将如何被称为主要.根据我的理解,pop函数不应该真正选择从堆栈弹出的内容.LIFO对吗?主要问题是Keytype&x参数究竟是什么以及如何在main中调用它?(在这种情况下,KeyType被初始化为KeyType*在此特定程序中堆叠一个int).