刚刚上完链式栈课,凭着理解写了个入栈的代码,调试不运行,求指教
程序代码:
#include <iostream> using namespace std; struct node { node *next; int data; }; class link { private: node *head; public: link(){head=NULL;} void cut(int i); void out(); }; void link::cut(int i) { node *s; s=new node; s->next=head->next; s->data = i; 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.cut(1); A.cut(2); A.cut(3); A.cut(4); A.cut(5); A.cut(6); A.cut(7); A.out(); }