C语言单链表和结构体的结合

2023-05-16

链表与结构体的结合,可以很好的方便输入输出,以后使用链表时只需要将结构体的信息稍作修改就可以使用,非常方便!!!
下面是写学生学号和姓名的结构体与链表的结合create函数!
1#include “stdio.h”
2
3typedef struct node{
4 int number;
5 char name[20];
6 }node;
7
8 typedef struct student{
9 node information;
10 struct student *next;
11 }student;
12
13 int iCount;
14
15 struct student *create()
16 {
17 int i;
18 node information;
19 struct student *head; //头指针 方便以后插入与删除等一系列操作
20 struct student *end; //位置指针
21 struct student *new; //创建空间的新指针
22 new = end = (struct student *)malloc(sizeof(student));
23 head = NULL;
24 if(new == NULL) //如果申请堆空间失败 则结束进程返回-1
25 {

26 printf(“申请空间失败\n”);

27 goto err;
28 }
29 printf(“请先输入学号,再输入姓名:\n”);
30 scanf(“%d”,&information.number);
31 scanf(“%s”,information.name);
32 new->information = information; //把结构体信息直接输入到链表中,方便快捷
33 for(i=0;new->information.number>0;i++)
34 {
35 iCount++;
36 if(iCount == 1)
37 {
38 new -> next = NULL;
39 end = new;
40 head = end;
41 }
42 else
43 {
44 new -> next = NULL;
45 end = new;
46 new = new -> next;
47 }
48 new = (struct student*)malloc(sizeof(student));
49 scanf(“%d”,&information.number);
50 scanf(“%s”,information.name);
51 new -> information = information;
52 }

53 return head;
54 err:
55 return -1;
56 }
57
58 int main()
59 {
60 student *A;
61 A = create();
62 return 0;
63 }

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C语言单链表和结构体的结合 的相关文章

  • python爬虫——模拟登陆

    参考链接 xff1a https blog csdn net weixin 39875941 article details 109878457 模拟登陆 Python网络爬虫应用十分广泛 xff0c 但是有些网页需要用户登陆后才能获取到信
  • vector数组 传递 引用 指针 参数

    一 一维 span class hljs stl container span class hljs built in vector span lt span class hljs keyword int span gt span vec
  • Oracle # 字符串匹配函数(Oracle、SQLSERVER、Excel)

    引言 xff1a 当数据库设置字段的时候 xff0c 会设置1表XXX xff1b 0表示XXX 查询的时候怎么显示汉字呢 xff1f Oracle数据库 xff1a 普通查询数据 xff1a select from U ORANGEZAT
  • 时间序列预测——Prophet模型

    文章链接 xff1a 时间序列预测 ARIMA模型 https blog csdn net beiye article details 123317316 spm 61 1001 2014 3001 5502 1 Propht模型概述 Pr
  • 机器人导航——路径跟踪

    要完成一套完整的机器人路径规划 xff0c 并完成其物理实验并非一件简单的事情 参考 xff1a http wenku baidu com link url 61 n11mP6EDlM78NZYZ4yQYXzmzPeBV6BeLNOUjIv
  • python 读取txt出现\xef\xbb\xbf…的问题

    用python读取txt文件 xff0c 文件的内容是一列数如下 xff1a 1883 1886 1900 1900 1897 1897 1897 1897 1906 1917 1910 1910 但是读取的时候第一个元素为 xef xbb
  • (算法)判断两个区间是否重叠

    题目 xff1a 判断两个区间是否重叠 思路 xff1a 假设区间表示为 start end xff0c 先存在两个区间A B 两个区间的关系有两种 xff1a 重叠与不重叠 重叠的情况有4种 xff0c 两种相交 xff0c 两种包含 x
  • python ctrl+c 退出while True:

    写了一个死循环 xff0c 类似 xff1a def function while True my code 程序运行后想用ctrl 43 c按键停止程序 xff0c 可是终止不了 以下为解决办法 xff1a 第一步 xff1a 加入sys
  • python二维字典

    感谢原文 xff1a http www jb51 net article 83108 htm 本文实例讲述了Python的 二维 字典 two dimension dictionary 定义与实现方法 分享给大家供大家参考 xff0c 具体
  • ros安装出现依赖问题

    http www liuxiao org 2015 10 ros E5 9C A8 ubuntu 14 04 E7 B3 BB E7 BB 9F E4 B8 8A E5 AE 89 E8 A3 85 ros indigo 0 安装环境 xf
  • KMP算法介绍

    参考 xff1a https www cnblogs com c cloud p 3224788 html 前言 之前对kmp算法虽然了解它的原理 xff0c 即求出P0 Pi的最大相同前后缀长度k xff1b 但是问题在于如何求出这个最大
  • 【python】*与** 参数问题

    原文地址 xff1a https www cnblogs com paulwinflo p 5764748 html 可变参数 在Python函数中 xff0c 还可以定义可变参数 顾名思义 xff0c 可变参数就是传入的参数个数是可变的
  • 计算机网络编程知识总结

    博客出处 xff1a http www cnblogs com maybe2030 阅读目录 1 网络层次划分 2 OSI七层网络模型 3 IP地址 4 子网掩码及网络划分 5 ARP RARP协议 6 路由选择协议 7 TCP IP协议
  • 机器学习——决策树(decision tree)

    相关文章链接 xff1a 机器学习 人工神经网络 xff08 NN xff09 机器学习 卷积神经网络 xff08 CNN xff09 机器学习 循环神经网络 xff08 RNN xff09 机器学习 长短期记忆 xff08 LSTM xf
  • 基于UDP的Winsock编程(C++版)

    基于UDP的Winsock编程与基于TCP的Winsock编程相比 xff0c 只是缺少了一个步骤而已 对于Server xff0c 缺少了接受连接的过程 xff08 accept 函数调用 xff09 xff1b 对于Client xff
  • Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven re

    Using insecure protocols with repositories without explicit opt in is unsupported Switch Maven repository maven4 http ma
  • 解析APK的AndroidManifest.xml

    将apk重命名zip解压后获取的AndroidManifest xml是加密后的 xff0c 如果需要看到里边的具体的内容信息 xff0c 需要使用AXMLPrinter2 jar来进行 1 网上下载工具AXMLPrinter2 jar工具
  • unity Symbolicate Android crash

    参考链接 https support unity com hc en us articles 115000292166 Symbolicate Android crash https docs unity3d com Packages co
  • 【无标题】

    Starting a Gradle Daemon 1 incompatible Daemon could not be reused use status for details Configure project launcher WAR

随机推荐