```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct girl
{
char name[20];
int age;
int num;
char grade[10];
}
struct Node
{
struct girl data;
struct Node*next;
};
struct Node*list = NULL;
struct Node*createList()
{
struct Node*headNode = (struct Node*)malloc(sizeof(struct Node));
headNode->next = NULL;
return headNode;
}
struct Node*createNode(struct girl data)
{
struct Node*newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->next = NULL;
return newNode;
}
void insertByHead(struct Node*headNode , struct girl data )
{
struct NOde*newNode = createNode(data);
newNode->next = headNode->next;
headNode->next = newNode;
}
void deleteByNum(struct Node*headNode, int posData)
{
struct Node*posFrontNode = headNode;
struct Node*posNode = headNode->next;
while(posNode != NULL&&posNode->data.num ! posData)
{
posFrontNode = posNode;
posNode = posFrontNode->next;
}
if(posNode == NULL)
{
printf("未找到指定位置,无法删除!\n");
}
else
{
posFrontNode->next = posNode ->next;
free(posNode);
posNode = NULL;
}
}
stuct Node*searchInfoByName(struct Node*headNode,char *name)
{
struct Node*pMove =headNode->next;
while(pMove!=NULL;strcmp(pMove->data.name,name))
{
pMove = pMove->next;
}
return pMove;
}
void printList(struct Node* headNode)
{
struct Node* pMove = headNode->next;
printf("name\tage\tnum\tgrade\n");
while(pMove)
{
printf("%s\t%d\t%d\t%s\n",pMove->data.name, pMove->data.age,pMove->data.num,pMove->data.grade);
pMove = pMove ->next;
}
}
void menuSystem()
{
printf("-------【起点】--------");
printf("\t\t0.退出系统\n");
printf("\t\t1.插入信息\n");
printf("\t\t2.浏览信息\n");
printf("\t\t3.查找信息\n");
printf("\t\t4.删除信息\n");
printf("\t\t5.修改信息\n");
printf("---------【路上】----------");
}
void keyDown()
{
int choic = 0;
scanf_s("%d",&choice);
struct girl tempData;
struct Node*pMove=NULL;
switch(choice)
{
case 0;
printf("正常退出!\n");
system("pause");
exit(0);
break;
case 1;
printf("请输入name,age,num,grade:");
scanf("%s%d%d%s",tempData.name, &tempData.age, &tempData.num, tempData.grade);
insertByHead(list,tempData);
break;
case 2;
printList();
break;
case 3;
printf("请输入查找的姓名:");
scanf("%s", tempData.name);
pMove=searchInfoByName(list,tempData.name)
if(searchInfoByName(list,tempData.name)=NULL)
{
printf("未找到相关信息");
}
else
{
printf("name\tage\tnum\tgrade\n");
printf("%s\t%d\t%d\t%s\n", pMove->data.name,pMove->data.age,pMove->data.num,pMove->data.grade);
break;
case 4;
printf("请输入删除的姓名:");
scanf("%s",tempData.name);
deleteByName(list,tempData.name);
break;
case 5;
printf("请输入修改信息的名字");
scanf("%s",tempData.name);
pMove = searchInfoByName(list, tempData.name;
if(pMove==NULL)
{
printf("无相关信息,无法修改!");
}
else
{
printf("请输入name,age,num,grade");
scanf("%s%d%d%s",pMove->data.name,pMove->data.age,pMove->data.num,pMove->data.grade);
printf("修改成功!");
}
break;
}
}
int main()
{
list = createList();
while(1)
{
menuSystem();
keyDown;
system("pause");
system("cls")
}
system("pause");
return 0;
}