3 Star 51 Fork 0

weh_coder / student_manage_system

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
list.c 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
weh_coder 提交于 2023-04-06 07:48 . add list.c.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include"list.h"
#include"fun.h"
//创建链表
struct List* createList()
{
struct List *list;
list=(struct List*)malloc(sizeof(struct List));
list->head=NULL;
list->size = 0;
return list;
}
//销毁链表
void destoryList(struct List *list)
{
struct Node *temp=list->head,*del=NULL;
while(temp)
{
del=temp;
temp=temp->next;
free(del);//释放节点空间
list->size--;
}
free(list);//释放链表空间
}
//创建节点
struct Node* createNode(struct Student student)
{
struct Node *node=NULL;
node=(struct Node*)malloc(sizeof(struct Node));
node->student=student;
node->next=NULL;
return node;
}
//获取链表最后一个节点
struct Node* getLastNode(struct List *list)
{
struct Node *temp=list->head,*last=NULL;
while(temp)
{
last=temp;
temp=temp->next;
}
return last;
}
//获取当前节点的上一个节点
struct Node* getBeforeNode(struct List *list,struct Student student)
{
struct Node *temp=list->head,*prevNode=NULL;
while(temp)
{
if(strcmp(temp->student.id,student.id)==0)
{
break;
}
prevNode=temp;
temp=temp->next;
}
return prevNode;
}
//将节点添加到链表中
void addList(struct List *list, struct Node *node)
{
struct Node *last;
if(list->head==NULL)
{
list->head=node;
}
else
{
last=getLastNode(list);
last->next=node;
}
list->size++;
}
C
1
https://gitee.com/weh_coder/student_manage_system.git
git@gitee.com:weh_coder/student_manage_system.git
weh_coder
student_manage_system
student_manage_system
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891