单链表
#include<stdio.h>
#include<stdlib.h>
struct student
{
int num;
char name[10];
struct student *next;
};
struct student *creat()
{
char ch;
struct student *add,*temp,*head;
head = (struct student *)malloc(sizeof(struct student));
head->next = NULL;
temp = head;
do
{
add=(struct student *)malloc(sizeof(struct student));
printf("请输入学生的学号和姓名:\n");
scanf("%d",&add->num);
scanf("%s",add->name);
temp->next=add;
temp=add;
printf("是否要添加新数据:(Y/N)");
fflush(stdin);
ch=getchar();
}while(ch=='y'||ch=='Y');
temp->next=NULL;
return head;
}
int main()
{
struct student *temp;
temp=creat()->next;
while(temp!=NULL)
{
printf("学号为:%d",temp->num);
printf("姓名为:%s",temp->name);
temp=temp->next;
}
}
这里使用链表创建并输出了信息,为以后管理系统铺垫。