动态列表

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student
{
char name[8];
int age;
struct student*kd;
};
void main()
{
struct student *help,*header=NULL;//malloc功能是动态开辟连续的内存空间
struct student p_current=(struct student)malloc(sizeof(struct student));
header=p_current;//header只是用一次 用来放张三的地址
help=p_current;//help的地址现在是101
strcpy(p_current->name ,“张三”);
p_current->age=19;

  p_current=(struct student*)malloc(sizeof(struct student));
  strcpy(p_current->name ,"李四");
	  p_current->age=20;
  help->kd =p_current;//张三的口袋放李四的坐标
  help=p_current;//help的地址变成了201

  p_current=(struct student*)malloc(sizeof(struct student));
  strcpy(p_current->name ,"王五");
	  p_current->age=21;
  help->kd =p_current;//李四的口袋放王五的坐标
  p_current->kd =NULL;//王五的口袋里现在没有地址
  
  puts("姓名     年龄");
  while(header!=0)
  {
	  printf("%s     %d\n",header->name ,header->age );
	  header=header->kd ;
  }

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值