看uCOS-II,第一个问题:不知道链表的意思

于是开始用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()里面输出创建的单链表

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值