可以这么设栈的结构体
struct stack
{
int data;
stack *down;
};
然后
stack *top = new stack;
top->down = NULL;
给出push的编法
void push( int n,stack *top )
{
stack *p = new stack;
p->data = n;
p->down = top;
top = p;
}
然后经过push,如果要计算结点个数,可以这样编。
int lenth( stack *top )
{
stacp *p = top;
int t = 0;
while ( p->down->down )
{
t++;
p = p->down;
}
return t;
}
.....不太看得动,应该节点就是top-1个啊