mirror of
https://gitee.com/apaki/cmake_demo.git
synced 2025-05-17 20:01:36 +08:00
59 lines
1003 B
C
59 lines
1003 B
C
|
|
#include "list.h"
|
|
|
|
void list_init(struct list_t *list)
|
|
{
|
|
list->data = 0;
|
|
list->next = NULL;
|
|
}
|
|
|
|
void list_add(struct list_t *list, uint8_t data)
|
|
{
|
|
struct list_t *p = NULL;
|
|
p = list;
|
|
while (p->next != NULL)
|
|
{
|
|
p = p->next;
|
|
if (p->data == data)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
p->next = (struct list_t *)malloc(sizeof(struct list_t));
|
|
p->next->data = data;
|
|
p->next->next = NULL;
|
|
return;
|
|
}
|
|
|
|
void list_print(struct list_t *list)
|
|
{
|
|
struct list_t *p = NULL;
|
|
p = list;
|
|
while (p->next != NULL)
|
|
{
|
|
printf("%02d ", p->data);
|
|
p = p->next;
|
|
if (p->next == NULL)
|
|
{
|
|
printf("%02d\n", p->data);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void list_free(struct list_t *list)
|
|
{
|
|
struct list_t *p = NULL;
|
|
p = list;
|
|
while (p->next != NULL)
|
|
{
|
|
p = p->next;
|
|
free(p->next);
|
|
p->next = NULL;
|
|
if (p->next == NULL)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|