填空题

以下程序实现栈的入栈和出栈的操作。其中有两个类:一个是节点类node,它包含点值和指向上一个节点的指针 prev;另一个类是栈类 stack, 它包含栈的头指针 top。
生成的链式栈如下图所示。
〈img src="tp/jsj/2jc++j28.1.gif"〉
下面是实现程序,请填空完成此程序。
#include 〈iostream〉
using namespace std;
class stack;
class node
int data;
node *prev;
public:
node(int d, node *n)

data=d;
prev=n;

friend class stack;
;
class stack
node *top; //栈头
public:
stack()

top=0;

void push(int i)

node *n=〈u〉 【13】 〈/u〉;
top=n;

int pop()

node *t=top;
if (top)

top=top-〉prev;
int c= t-〉data;
delete t;
return c;

return 0;

int main ()

stack s;
s.push(6);
s.push(3);
s.push (1);
return 0;

【参考答案】

new node(i,top)