/*
*Copyright(c)2014,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:asd.cpp
*作 者:綦鹏
*完成日期:2016年3月28日
*版 本 号: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<5;i++)
{
STUDENT *stu;
stu=(STUDENT *)malloc(sizeof(STUDENT));
// strcpy(stu->name,"zhangsan");
sprintf(stu->name,"%s%d","zhangsan",i+1);
addStudent(stu);
}
}
void addStudent(STUDENT *stu)
{
STUDENT *p;
if(gStu==NULL)
{
gStu=stu;
gStu->next=NULL;
}
else
{
p=gStu;
while(p)
{
if(p->next==NULL)
{
p->next=stu;
stu->next=NULL;
}
p=p->next;
}
}
}
链表
最新推荐文章于 2022-07-26 21:57:51 发布