作者在 2008-05-06 21:52:05 发布以下内容
#include<stdio.h>
#include<stdlib.h>
typedef struct node{int data;struct node *link;}LNode;
LNode *createfirst()
{
LNode *s,*h;
int x,tag;
h=NULL;
printf("结束符号:");
scanf("%d",&tag);
printf("输入数据:");
scanf("%d",&x);
while(x!=tag)
{
s=(LNode *)malloc(sizeof(LNode));
s->data=x;
s->link=h;
h=s;
scanf("%d",&x);
}
return h;
}
void myprint(LNode *h)
{
LNode *p;
p=h;
if(p==NULL)
printf("空链\n");
else
{
printf("%5d",p->data);
p=h->link;
do
{
printf("%5d",p->data);
p=p->link;
}
while(p!=NULL);
}
printf("\n");
}
main()
{
LNode *h;
h=createfirst();
myprint(h);
}
#include<stdlib.h>
typedef struct node{int data;struct node *link;}LNode;
LNode *createfirst()
{
LNode *s,*h;
int x,tag;
h=NULL;
printf("结束符号:");
scanf("%d",&tag);
printf("输入数据:");
scanf("%d",&x);
while(x!=tag)
{
s=(LNode *)malloc(sizeof(LNode));
s->data=x;
s->link=h;
h=s;
scanf("%d",&x);
}
return h;
}
void myprint(LNode *h)
{
LNode *p;
p=h;
if(p==NULL)
printf("空链\n");
else
{
printf("%5d",p->data);
p=h->link;
do
{
printf("%5d",p->data);
p=p->link;
}
while(p!=NULL);
}
printf("\n");
}
main()
{
LNode *h;
h=createfirst();
myprint(h);
}