代码拉取完成,页面将自动刷新
#include <stdlib.h>
#include <string.h>
#include "list.h"
int list_init(List *list, void (*destroy)(void *data)) {
if (list == NULL) {
return -1;
}
list->size = 0;
list->head = NULL;
list->tail = NULL;
list->destroy = destroy;
return 0;
}
void list_destroy(List *list) {
void *data;
while (list_size(list) > 0) {
if (list_delete_after(list, NULL, (void **)&data) > 0
&& list->destroy != NULL) {
list->destroy(data);
}
}
memset(list, 0, sizeof(List));
return;
}
int list_insert_after(List *list, ListElem *ele, const void *data) {
ListElem *tmpElem;
if ((tmpElem = (ListElem *)malloc(sizeof(ListElem))) == NULL) {
return -1;
}
tmpElem->data = (void *)data;
if (ele == NULL) {
if (list_size(list) == 0) {
list->tail = tmpElem;
}
tmpElem->next = list->head;
list->head = tmpElem;
} else {
if (ele->next == NULL) {
list->tail = tmpElem;
}
tmpElem->next = ele->next;
ele->next = tmpElem;
}
list->size++;
return 0;
}
int list_delete_after(List *list, ListElem *ele, void **data) {
ListElem *tmpElem;
if (list_size(list) == 0) {
return -1;
}
if (ele == NULL) {
tmpElem = list->head;
list->head = list->head->next;
if (list_size(list) == 1) {
list->tail = NULL;
}
} else {
if (ele->next == NULL) {
return -1;
}
tmpElem = ele->next;
ele->next = ele->next->next;
if (ele->next == NULL) {
list->tail = ele;
}
}
*data = tmpElem->data;
free(tmpElem);
list->size--;
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。