diff --git a/education/software development/ECE1400/Chapter 17 Exercises.md b/education/software development/ECE1400/Chapter 17 Exercises.md index 5149ff8..53868b1 100644 --- a/education/software development/ECE1400/Chapter 17 Exercises.md +++ b/education/software development/ECE1400/Chapter 17 Exercises.md @@ -42,7 +42,7 @@ The above loop won't function because it deallocates the entry, then attempts to A functional example might look like this: ```c -struct entry* p = first; +struct entry *p = first; while (p != NULL) { void *current = p; p = p->next; @@ -58,4 +58,15 @@ while (p != NULL) { --- -> **13.** The following function is supposed to insert a new node into its proper place in an ordered list, returning a pointer to the first node in the modified list. Unfortunately \ No newline at end of file +> **13.** The following function is supposed to insert a new node into its proper place in an ordered list, returning a pointer to the first node in the modified list. Unfortunately, the function doesn't work correctly in all cases. Explain what's wrong with it and show how to fix it. Assume that the `node` structure is the one defined in Section 17.5. +```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->next = new_node; + new_node->next = cur; + return list; +} +``` \ No newline at end of file