Skip to content
Snippets Groups Projects
Commit 29157297 authored by antoine.giles's avatar antoine.giles
Browse files

ca free pas, liste est considérée comme nulle

parent fbb0605c
No related branches found
No related tags found
No related merge requests found
ex3/main 0 → 100755
File added
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <stdbool.h> #include <stdbool.h>
typedef struct element{ typedef struct element{
int data; float data;
struct element* next; struct element* next;
struct element* prev; struct element* prev;
} element; } element;
...@@ -27,20 +27,20 @@ element* dll_push(element* head, int data){ ...@@ -27,20 +27,20 @@ element* dll_push(element* head, int data){
head->prev = new; head->prev = new;
new->next = head; new->next = head;
} }
printf("created element with data = %d\n", new->data); printf("created element with data = %f\n", new->data);
return new; return new;
} }
void dll_print(element *head){ void dll_print(element *head){
/*if(dll_empty){ if(dll_empty){
printf("list is empty\n"); printf("list is empty\n");
return; return;
}*/ }
while(head->next != NULL){ while(head->next != NULL){
printf("%d->", head->data); printf("%f->", head->data);
head = head->next; head = head->next;
} }
printf("%d", head->data); printf("%f\n", head->data);
} }
void dll_destroy(element* head){ void dll_destroy(element* head){
...@@ -59,19 +59,20 @@ int main(){ ...@@ -59,19 +59,20 @@ int main(){
printf("entrez la liste "); printf("entrez la liste ");
int length = 0; int length = 0;
scanf("%d", &length); scanf("%d", &length);
int* tab = malloc(length*sizeof(int)); float* tab = malloc(length*sizeof(float));
for(int i = 0; i< length; i++){ for(int i = 0; i< length; i++){
scanf("%d", &tab[i]); scanf("%f", &tab[i]);
} }
element* lst1 = dll_create(); element* lst1 = dll_create();
for(int i = 0; i< length; i++){ for(int i = 0; i< length; i++){
lst1 = dll_push(lst1, tab[i]); lst1 = dll_push(lst1, tab[i]);
if(lst1->next != NULL){ if(lst1->next != NULL){
printf("lst1->next->data = %d\n", lst1->next->data); printf("lst1->next->data = %f\n", lst1->next->data);
} }
} }
dll_print(lst1);
dll_destroy(lst1); dll_destroy(lst1);
......
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment