X-Git-Url: https://git.piment-noir.org/?p=TD_C.git;a=blobdiff_plain;f=TP_11%2Fexo2%2Flib%2Fclist.c;h=303115419a8e27dafa4286d8399c8a948260bf5f;hp=244a6877d31f111d79ea9aed02bbeb2eefdb186d;hb=5d64063095177554839e67ddc73193929f115d07;hpb=2737ed7c252e5f624b8f98cbe28eb05450c9420e diff --git a/TP_11/exo2/lib/clist.c b/TP_11/exo2/lib/clist.c index 244a687..3031154 100644 --- a/TP_11/exo2/lib/clist.c +++ b/TP_11/exo2/lib/clist.c @@ -34,10 +34,11 @@ link_t* list_prepend(link_t* head, int value) { } link_t* list_insert(link_t* head, unsigned index, int value) { + unsigned max_index = list_count(head); if (index == 0) { return list_prepend(head, value); - } else if (index == list_count(head)) { + } else if (index == max_index) { return list_append(head, value); } else { link_t* link_insrt = list_new(value); @@ -58,7 +59,7 @@ link_t* list_delete(link_t* head, unsigned index) { link_t* head_prev = NULL; link_t* head_next = NULL; link_t* head_ret = NULL; - + if (head == NULL) { return NULL; } else if (index == 0) { @@ -209,8 +210,8 @@ void list_display_values(link_t* head) { printf("------Begin------\n"); while (head != NULL) { printf("value at [%d]=%d\n", i, head->value); - head = head->next; - i++; + head = head->next; + i++; } printf("------End------\n"); }