于是开始用C编写一个单链表的输入输出程序
#include <stdio.h >
#include <conio.h >
#include <malloc.h>
#include <string.h>
#include <ctype.h >
#include <stdlib.h>
#include <dos.h >
#include <setjmp.h>
#include <bios.h >
#define NULL 0
struct node
{
int info;
struct node *next;
};
struct node *create(void)
{
int data;
struct node *head;
struct node *tail;
struct node *node1;
head=(struct node*)malloc(4);
tail=head;
printf("1 /n");
scanf("%d ",&data);
while(data!=0)
{
node1=(struct node*)malloc(4);
node1->info=data;
tail->next=node1;
tail=node1;
data=data;
data=data;
printf("2 /n");
scanf("%d",&data);
}
tail->next=NULL;
return head;
}
unsigned int main(void)
{
struct node *headd;
struct node *xyz=NULL;
headd= create();
xyz->next=headd->next;
while(xyz->next!=NULL)
{
printf("headd->next %d /n",*xyz->next);
xyz->next=xyz->next->next;
}
getch();
return 0;
}
//unsigned char x=0;
//x=sizeof(struct node);
测试OK,代码功能:
随意输入n个整数(此整数不能为0,为0结束输入),按照输入的顺序组成一个单链表。(creat(void)功能)
main()里面输出创建的单链表