diff --git a/education/software development/ECE1400/Chapter 17 Exercises.md b/education/software development/ECE1400/Chapter 17 Exercises.md index 53868b1..78e449d 100644 --- a/education/software development/ECE1400/Chapter 17 Exercises.md +++ b/education/software development/ECE1400/Chapter 17 Exercises.md @@ -63,7 +63,22 @@ while (p != NULL) { 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) { - + prev = cur; + cur = cur->next; + } + prev->next = new_node; + new_node->next = cur; + return list; +} +``` + + +```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) { + prev = cur; + cur = cur->next; } prev->next = new_node; new_node->next = cur;