diff --git a/exo1/exo1.c b/exo1/exo1.c index fd212cefb93b18dbc0eb718dab0a3753e501ca15..10f2f2babafa559716f43378edb5cec765cb8dc9 100644 --- a/exo1/exo1.c +++ b/exo1/exo1.c @@ -5,9 +5,211 @@ #include <stdlib.h> #include <stdbool.h> #include <time.h> +#include <malloc.h> + +typedef struct _element +{ + int data; + struct _element *next; +}element; + +typedef struct _list +{ + element *head; + element *pos; +}list; + + +void list_destroy(list *list) +{ + list->pos = list->head; + while(list->pos->next != NULL) + { + element *tmp = list->pos; + list->pos = list->pos->next; + free(tmp); + } + + free(list->pos); +} + +int array_pop(element *array) +{ + element *tmp = array; + array = array->next; + int value = tmp->data; + + return value; +} + +void print_list(list *list) +{ + list->pos = list->head; + while (list->pos->next != NULL) + { + printf("%i ", list->pos->data); + list->pos = list->pos->next; + } + + printf("%i ", list->pos->data); +} + +int read_list(list *list) +{ + list->pos = list->head; + if (list->pos->next != NULL) + { + list->pos = list->pos->next; + } + + return list->pos->data; +} + int main() { + printf("Entrez la liste \n"); + + int list_length1; + scanf("%i", &list_length1); + + list list1; + + for(int i = 0; i < list_length1; i++) + { + element *elem = malloc(sizeof(*elem)); + if(list1.head != NULL) + { + elem->next = list1.head; + + } + else + { + elem->next = NULL; + } + + + int value; + scanf("%i", &value); + + elem->data = value; + list1.head = elem; + } + + printf("Entrez la liste \n"); + + int list_length2; + scanf("%i", &list_length2); + + list list2; + + for(int i = 0; i < list_length2; i++) + { + element *elem = malloc(sizeof(*elem)); + if(list2.head != NULL) + { + elem->next = list2.head; + + } + else + { + elem->next = NULL; + } + + + int value; + scanf("%i", &value); + + elem->data = value; + list2.head = elem; + } + + int values[list_length1+list_length2]; + + for (int i = 0; i < list_length1; i++) + { + values[i] = read_list(&list1); + } + + for (int i = list_length1; i < list_length2 + list_length1; i++) + { + values[i] = read_list(&list2); + } + + + printf("intersection : \n"); + for(int i = 0; i< list_length1 + list_length2; i++) + { + printf("%i", values[i]); + } + + printf("\n"); + + + // list sorted_list_intersection; + + // list1.pos = list1.head; + // for(int i = 0; i < list_length1; i++) + // { + // int value = list1.pos->data; + + // if(list1.pos->next != NULL) + // { + // list1.pos = list1.pos->next; + // } + + + // element *elem = malloc(sizeof(*elem)); + // if(sorted_list_intersection.head != NULL) + // { + // sorted_list_intersection.pos = sorted_list_intersection.head; + + // while(sorted_list_intersection.pos->next != NULL && value > sorted_list_intersection.pos->data) + // { + // sorted_list_intersection.pos = sorted_list_intersection.pos->next; + // } + + // if(sorted_list_intersection.pos->next != NULL) + // { + // element *tmp = sorted_list_intersection.pos->next; + // sorted_list_intersection.pos->next = elem; + // elem->next = tmp; + // } + // else + // { + // sorted_list_intersection.pos->next = elem; + // } + + // } + // else + // { + // elem->next = NULL; + // sorted_list_intersection.head = elem; + // } + + // elem->data = value; + + // } + + print_list(&list1); + + print_list(&list2); + + // print_list(&sorted_list_intersection); + + list_destroy(&list1); + list_destroy(&list2); + // list_destroy(&sorted_list_intersection); + // for(int i = 0; i < array_length1; i++) + // { + // printf("%i", array_pop(array1)); + // } + + // printf("%i", array_length1); + + // free_array(array1); } + + diff --git a/exo3/exo3 b/exo3/exo3 deleted file mode 100755 index 0d88bfeeaf312d91642873bfed9acdf5fa6b9111..0000000000000000000000000000000000000000 Binary files a/exo3/exo3 and /dev/null differ