#include "list.h" void list_init(struct list** _listroot) { if(*_listroot) while(list_popFront(_listroot)); *_listroot = NULL; } void list_add(int _data, struct list** _listroot) { struct list **current = _listroot; while(*current) current = &(*current)->next; *current = malloc(sizeof(**current)); (*current)->data = _data; } int list_popFront(struct list** _listroot) { if(!*_listroot) return 0; int data = (*_listroot)->data; struct list *oldRoot = *_listroot; *_listroot = (*_listroot)->next; free(oldRoot); return data; } int list_get(int _index, struct list** _listroot) { struct list* current = *_listroot; for(int i = 0; i < _index; i++) { current = current->next; } return current->data; }