From 56b77cc8ff6fb04623f5137b6839cb199c29ad47 Mon Sep 17 00:00:00 2001 From: zleyyij <75810274+zleyyij@users.noreply.github.com> Date: Tue, 19 Nov 2024 22:05:20 -0700 Subject: [PATCH] vault backup: 2024-11-19 22:05:20 --- .../software development/ECE1400/Chapter 17 Exercises.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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; }