单向链表程序 求助
程序编译没有问题 但是没有办法运行 【平台是VC6.0】
程序代码:
#include<stdio.h>
struct node
{
int data;
node *link;
};
struct list
{
node *first,*last;
};
int insert(list a,int num)
{
node *p=a.first;
while(p!=NULL) p=p->link;
node *m;
m->data=num;
m->link=NULL;
if(a.first==NULL)
{
m->link=a.first;
if(a.first==NULL) a.last=m;
a.first=m;
}
else
{
m->link=p->link;
if(p->link==NULL) a.last=m;
p->link=m;
}
return 0;
}
int show(const list a)
{
node *p=a.first;
while(p!=NULL)
{
printf("%d ",&p->data);
p=p->link;
};
return 0;
}
int main()
{
list a;
a.first=a.last=NULL;
for(int i=0;i<4;i++)
insert(a,i+1);
show(a);
return 0;
}
[ 本帖最后由 韭菜 于 2010-9-27 02:18 编辑 ]










哈哈