list: Permet d'insérer et de récupérer la taille

This commit is contained in:
2022-10-14 09:48:26 +02:00
parent 03b7ee8494
commit cb6d978cad
4 changed files with 33 additions and 0 deletions

View File

@@ -1,11 +1,32 @@
#include "linkedList.h"
#include <stdio.h>
#include <stdlib.h>
LinkedList createLinkedList(void) {
return NULL;
}
void insertAtListHead(LinkedList *list, int value) {
struct list_node *node = malloc(sizeof(struct list_node));
if (node == NULL) {
fprintf(stderr, "Memory exhausted!\n");
abort();
}
node->value = value;
node->next = *list;
*list = node;
}
int linkedListLength(LinkedList list) {
int n = 0;
while (list != NULL) {
n += 1;
list = list->next;
}
return n;
}
void freeLinkedList(LinkedList *list) {
struct list_node *next;
struct list_node *node = *list;