#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Student{
char Name[20];
char Number[10];
struct Student *next;
};
int Count;
struct Student *Create(){
struct Student *pHead = 0;
struct Student *pEnd,*pNew;
Count = 0;
pEnd = pNew =(struct Student *)malloc(sizeof(struct Student));
printf("请输入学生的姓名和学号:(姓名和学号都为0时结束录入)\n");
scanf("%s",&pNew->Name);
scanf("%s",&pNew->Number);
while((strcmp("0",pNew->Number)!=0)||(strcmp("0",pNew->Name)!=0)){
Count++;
if(Count==1){
pNew->next = pHead;
pHead=pNew;
pEnd=pNew;
}
else{
pNew->next = 0;
pEnd->next=pNew;
pEnd=pNew;
}
pNew=(struct Student *)malloc(sizeof(struct Student));
scanf("%s",&pNew->Name);
scanf("%s",&pNew->Number);
}
printf("\n信息录入成功\n\n");
free(pNew);
return pHead;
}
struct Student *AddNodeToTheHead(struct Student *pHead){
struct Student *pNew;
pNew = (struct Student *)malloc(sizeof(struct Student));
printf("请输入添加到开头的学生姓名、学号:(输入cancel中止添加)\n");
scanf("%s",&pNew->Name);
if(strcmp("cancel",pNew->Name)==0)return pHead;
scanf("%s",&pNew->Number);
pNew->next = pHead;
pHead = pNew;
Count++;
printf("\n添加到开头成功!\n\
单链表-姓名学号-创建/遍历/增添/删除
最新推荐文章于 2024-04-23 18:02:34 发布