Skip to content
Snippets Groups Projects
Commit 62114c86 authored by william.ho's avatar william.ho
Browse files

ex3 pas fini

parent af3fcc70
No related branches found
No related tags found
No related merge requests found
ex3/main 0 → 100755
File added
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
typedef struct _element { // Elément de liste
int data;
struct _element* next;
} element_t;
typedef struct _ddl {
element_t* head;
element_t* pos;
} dll_t;
void free_liste(element_t* liste1){
element_t* prec = liste1;
element_t* current = liste1;
while(current->next != NULL){
prec = current;
current = current->next;
free(prec);
}
free(current);
}
dll_t* dll_create(){
dll_t* new = malloc(sizeof(dll_t));
new->head = NULL;
new->pos = NULL;
return new;
}
void dll_print(dll_t* liste){
if(liste != NULL){
element_t* current = liste->head;
while(current != NULL){
printf("%d ", current->data);
current = current->next;
}
printf("\n");
}else{
printf("Empty");
}
}
void dll_destroy(dll_t* liste){
free_liste(liste->head);
free(liste->pos);
free(liste);
}
void dll_push(dll_t* liste, int data){
element_t* new = malloc(sizeof(element_t));
new->data = data;
new->next = liste->head;
liste->head = new;
}
int main(){ int main(){
int size, tmp;
dll_t* liste = dll_create();
printf("Liste d'entiers : ");
scanf("%d", &size);
while(size > 0){
scanf("%d", &tmp);
dll_push(liste, tmp);
size --;
}
dll_print(liste);
dll_destroy(liste);
return(0); return(0);
} }
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment