刚刚上完链式栈课,凭着理解写了个入栈的代码,调试不运行,求指教
#include <iostream>栈
using namespace std;
struct node
{
node *next;
int data;
};
class link
{
private:
node *head;
public:
link(){head=NULL;}
void push(int i);
void out();
};
void link::push(int i)
{
node *s;
s=new node;
s->data = i;
s->next=head->next;
head->next=s;
}
void link::out()
{
node *p;
p = head;
while(p->next==NULL)
{
p=p->next;
cout<<p->data<<endl;
}
}
void main()
{
link A;
A.push(1);
A.push(2);
A.push(3);
A.out();
}