巩固了一下单链表的知识点,并运用单链表写了个简单的学生管理系统
实现功能:增、删、改、查
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student
{
char name[20];
int age;
};
//定义单链表
typedef struct SingleList
{
struct student mystudent;
struct SingleList *next;
}LIST,*LPLIST;
//创建带有表头的单链表
LPLIST CreatList()
{
//申请内存
LPLIST List = (LPLIST)malloc(sizeof(LIST));
//初始化基本数据成员
List->next = NULL;
return List;
}
//创建节点
LPLIST CreatNode(struct student mystudent)
{
//申请内存
LPLIST Node = (LPLIST)malloc(sizeof(LIST));
//初始化基本数据成员
strcpy((Node->mystudent).name,mystudent.name);
(Node->mystudent).age = mystudent.age;
Node->next = NULL;
return Node;
}
//表头插入
void InsertHead(LPLIST List, struct student mystudent)
{
LPLIST pNode = CreatNode(mystudent);
pNode->next = List->next;
List->next = pNode;
}
//表尾插入
void InsertTail(LPLIST List, st