diff --git a/education/software development/ECE1400/Chapter 17 Exercises.md b/education/software development/ECE1400/Chapter 17 Exercises.md index 1ebd569..67adf53 100644 --- a/education/software development/ECE1400/Chapter 17 Exercises.md +++ b/education/software development/ECE1400/Chapter 17 Exercises.md @@ -72,11 +72,14 @@ struct node *insert_into_ordered_list(struct node *list, struct node *new_node) } ``` -In the above code, if the new item needs to be ine +In the above code, if the new item needs to be inserted at the *end* of the list, it breaks, because `cur` is set to `NULL`, then it attempts to access `cur->value`. ```c struct node *insert_into_ordered_list(struct node *list, struct node *new_node) { struct node *cur = list, *prev = NULL; while (cur->value <= new_node->value) { + if (cur->next == NULL) { + break; + } prev = cur; cur = cur->next; }