35 lines
859 B
C
35 lines
859 B
C
/****** llist.c
|
|
This file contains the functions for accessing and manipulating the linked list struct, LList.
|
|
******/
|
|
#include <stdlib.h>
|
|
#include "llist.h"
|
|
|
|
/*
|
|
================================
|
|
struct LList *newLList()
|
|
|
|
This function is used to malloc, initialize, and then return a new LList.
|
|
================================
|
|
*/
|
|
struct LList *newLList() {
|
|
struct LList *llist = malloc(sizeof(struct LList));
|
|
llist->size = 0;
|
|
llist->next = NULL;
|
|
llist->data = NULL;
|
|
return llist;
|
|
}
|
|
|
|
/*
|
|
================================
|
|
int freeLList(struct LList *llist)
|
|
|
|
This function takes a LList pointer and attempts to free the LList's data property, if non-NULL, and thereafter free()s the LList itself.
|
|
================================
|
|
*/
|
|
int freeLList(struct LList *llist) {
|
|
if (llist->data != NULL)
|
|
free(llist->data);
|
|
free(llist);
|
|
return 0;
|
|
}
|