1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| #include <stdlib.h>
#include <stdio.h>
#include "list.h"
struct Cell
{
int integer;
struct Cell *next;
};
struct LinkedList
{
struct Cell *first;
struct Cell *it;
};
void createListe(struct LinkedList *list) /* Initialise la list */
{
list->first = NULL;
list->it = NULL;
}
void deleteListe(struct LinkedList *list)
{
list->it = list->first;
struct Cell *temp;
while((list->it)->next != NULL)
{
temp = (list->it)->next;
free(list->it);
list->it = temp;
}
free(list->it);
list->it = NULL;
list->first = NULL;
}
void incrementIt(LinkedList *list)
{
list->it = (list->it)->next;
}
void push(struct LinkedList *list, int x)
{
struct Cell *p = malloc(sizeof(struct Cell));
p->next = list->first; // First vaut NULL si la list est vide
p->integer = x;
list->first = p;
list->it = p;
}
void printList(struct LinkedList *list)
{
list->it = list->first;
if(list->it == NULL)
printf("<empty>");
while(list->it != NULL)
{
printf("%d ", (list->it)->integer);
list->it = (list->it)->next;
}
printf("\n");
} |