65,211
社区成员
发帖
与我相关
我的任务
分享
// ConsoleTest.cpp : Defines the entry point for the console application.
//
#include <iostream>
using namespace std;
template <class Type>
class Stack
{
private:
struct node
{
Type data;
node * link;
};
node * top;
public:
Stack()
{
top = NULL;
}
~Stack()
{
node * temp;
while (top)
{
temp = top;
top = top->link;
delete temp;
}
}
inline bool Push(const Type item)
{
node * temp = new node;
if (temp)
{
temp->data = item;
temp->link = top;
top = temp;
return true;
}
return false;
}
inline bool Pop(Type & item)
{
if (StackEmpty())
{
cout << "The stack is empty." << endl;
return false;
}
else
{
item = top->data;
node * temp = top;
top = top->link;
delete temp;
return true;
}
}
inline bool StackEmpty()
{
return (top == NULL);
}
};
int main()
{
Stack s; // error here!
return 0;
}
Stack s; // error here! Stack<int> s; // error here!