[代码记录] C语言链表
2024-10-08 09:24:23
#开始
· 简单的创建链表
#代码
#include<conio.h>
#include<stdio.h>
#include<stdlib.h> struct Str
{
char name[];
int sex;
int id;
Str * next;
}; void printStruct(Str *str) //输出链表
{
Str *strTemp = str;
while(strTemp->next)
{
printf("=========print=============\n");
printf("id: %d\n",strTemp->id);
printf("name: %s\n",strTemp->name);
printf("sex: %d\n",strTemp->sex);
strTemp = strTemp->next;
}
} int main()
{
Str* strFirst = (Str*)malloc(sizeof(Str));
Str* strTemp = strFirst;
while(strTemp->next) //创建链表
{
printf("=========================\n");
printf("输入id:");
scanf("%d",&strTemp->id);
if(strTemp->id == ) //如果输入id == 0 就退出输入
{
strTemp->next = NULL; //给next赋值NULL 并且返回到循环的最开始的位置
continue;
}
printf("输入name:");
scanf("%s",strTemp->name); printf("输入sex:");
scanf("%d",&strTemp->sex); strTemp->next=(Str*)malloc(sizeof(Str));
strTemp = strTemp->next;
}
printStruct(strFirst); //输出链表 _getch();
return ;
}
#运行环境
win7 32位
VS2010
最新文章
- Client病毒已感染超7万人 暗扣费并频弹广告
- json字符串返回到js中乱码
- 堆糖瀑布流完整解决方案(jQuery)
- Exception mybatis 配置文件:<;typeAlias alias=";***"; type=";***";/>; 重复配置
- ios学习笔记
- JSON未定义解决办法
- 20180519001 - DataTable Group by功能参考
- Java核心技术卷一基础知识-第5章-继承-读书笔记
- Linux安装Tomcat-Nginx-FastDFS-Redis-Solr-集群——【第十集之Nginx反向代理原理】(有参考其他文章)
- mac安装pyspider报错
- SQL Server 2016 发送邮件功能
- [LeetCode] 744. Find Smallest Letter Greater Than Target_Easy tag: **Binary Search
- 理解本真的 REST 架构风格
- Go语言学习之5 进阶-排序、链表、二叉树、接口
- 20171126--fragment的小项目
- (转)CloudStack 安装及使用过程中常见问题汇总
- Deep Learning 教程(斯坦福深度学习研究团队)
- VS2017专业版使用最新版Qt5.9.2教程
- python为什么需要reload(sys)后设置编码
- Hadoop Streaming:aggregate