50 lines
673 B
C
50 lines
673 B
C
/*
|
|
* list.c
|
|
*
|
|
* Created on: Jul 27, 2016
|
|
* Author: tkl
|
|
*/
|
|
|
|
#include "stddef.h"
|
|
#include "list.h"
|
|
|
|
int list_init(struct list *head)
|
|
{
|
|
if(NULL == head)
|
|
return -1;
|
|
|
|
head->front = NULL;
|
|
head->rear = NULL;
|
|
|
|
return 0;
|
|
}
|
|
|
|
int list_add(struct list *head, struct list_node *node)
|
|
{
|
|
if((NULL == head) || (NULL == node))
|
|
return -1;
|
|
|
|
if(head->front == NULL) {
|
|
head->front = node;
|
|
head->rear = node;
|
|
}
|
|
else {
|
|
head->rear->next = node;
|
|
head->rear = node;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
int list_get_len(struct list *head)
|
|
{
|
|
int ret = 0;
|
|
if(NULL == head)
|
|
return -1;
|
|
struct list_node *it = head->front;
|
|
while(NULL != it) {
|
|
ret++;
|
|
it = it->next;
|
|
}
|
|
return ret;
|
|
}
|