zoukankan      html  css  js  c++  java
  • C语言链表的基本操作

    */
     * Copyright (c) 2016,烟台大学计算机与控制工程学院
     * All rights reserved.
     * 文件名:text.cpp
     * 作者:常轩
     * 微信公众号:Worldhello
     * 完成日期:2016年4月230日
     * 版本号:V1.0
     * 问题描述:链表的基本操作
     * 程序输入:无
     * 程序输出:见运行结果
     */
    #include"stdio.h"
    #include"stdlib.h"
    #include"string.h"
    struct STUDENT{
    
    	char name[32];
    	struct STUDENT  *next;
    };
    void addStudent(STUDENT *stu);
    STUDENT *gStu=NULL;
    void main()
    {
    	int i;
    	for(i=0;i<100;i++)
    	{
    		 STUDENT *stu;
    		 stu=(STUDENT *)malloc(sizeof(STUDENT));
    		 sprintf(stu->name,"%s%d","student ",i+1);
    		 addStudent(stu);
    	}
    	STUDENT *p;
    	p=gStu;
    	while(p)
    	{
    		printf("%s
    ",p->name);
    		p=p->next;
    	}
    }
    void addStudent(STUDENT *stu)
    {
    	STUDENT *p;
    	if(gStu==NULL)
    	{
    		gStu=stu;
    		stu->next=NULL;
    	}
    	else
    	{
    		p=gStu;
    		while(p)
    		{
    			if(p->next==NULL)
    			{
    				p->next=stu;
    				stu->next=NULL;
    			}
    			p=p->next;
    		}
    	}
    }

    运行结果:


    心得:

           当理解后,感觉老师说的一个比喻非常恰当“链表”就是一条自行车的车链子

  • 相关阅读:
    输入一批整数,输出最大最小值,输入0结束
    获取最低价手机价格
    插入数值
    猜数游戏
    数字金字塔
    输出星期数
    9*9乘法表
    linux 出core设置问题
    linux socket连接中 ERRNO错误
    linux c 获取头文件函数getenv
  • 原文地址:https://www.cnblogs.com/chxuan/p/8232232.html
Copyright © 2011-2022 走看看