From: Jérôme Benoit Date: Tue, 7 Mar 2017 20:33:22 +0000 (+0100) Subject: TP11 exo2: Finish the asked features implementation X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=fabfe86c7978e83ae992422469a7b4da89e3081f;p=TD_C.git TP11 exo2: Finish the asked features implementation Signed-off-by: Jérôme Benoit --- diff --git a/TP_11/exo2/exo2.c b/TP_11/exo2/exo2.c index ca9df42..65e791b 100644 --- a/TP_11/exo2/exo2.c +++ b/TP_11/exo2/exo2.c @@ -1,47 +1,34 @@ +#include #include +#include -#include "clist.h" #include "ui.h" int main() { - link_t* head1 = NULL; - link_t* head2 = NULL; link_t* head = NULL; + unsigned counter = 0; + int value = 0; + int promptrtVal = 0; + int* array = NULL; - printf("Longueur de la liste: %d\n", list_count(head1)); - head1 = list_append(head1, 1); - head1 = list_append(head1, 2); - head1 = list_append(head1, 3); - head1 = list_append(head1, 4); - printf("Longueur de la liste: %d\n", list_count(head1)); - displayList(head1); - head1 = list_prepend(head1, 5); - printf("Longueur de la liste: %d\n", list_count(head1)); - displayList(head1); - list_set(head1, 0, 78); - displayList(head1); - head1 = list_insert(head1, 2, 7); - displayList(head1); - head1 = list_delete(head1, 3); - displayList(head1); - head1 = list_append(head1, 5); - head1 = list_append(head1, 12); - head1 = list_append(head1, 65); - head1 = list_append(head1, 21); - head1 = list_sort(head1); - displayList(head1); - head2 = list_insert(head2, 0, 8); - head2 = list_append(head2, 6); - head2 = list_prepend(head2, 5); - displayList(head2); - head = list_concat(head1, head2); + while (true) { + promptrtVal = promptValue("Saisir une valeur:", &value); + if (promptrtVal != 0) + break; + head = list_append(head, value); + counter++; + } + printf("Liste:\n"); displayList(head); - head = list_merge_sort(head); - //head = list_sort(head); - displayList(head); - //list_clear(head1); - //list_clear(head2); + array = malloc(counter*sizeof(int)); + array[0] = list_get(head, 0); + for (unsigned i = 1; i < counter; i++) { + array[i] = array[i-1] + list_get(head, i); + } + printf("Tableau des sommes:\n"); + displayArray(array, counter); list_clear(head); + free(array); return 0; }