}
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);
link_t* head_prev = NULL;
link_t* head_next = NULL;
link_t* head_ret = NULL;
-
+
if (head == NULL) {
return NULL;
} else if (index == 0) {
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");
}