From b677e73bbe9c4d63157d256d5904c6d44c812402 Mon Sep 17 00:00:00 2001 From: zleyyij <75810274+zleyyij@users.noreply.github.com> Date: Tue, 19 Nov 2024 21:49:36 -0700 Subject: [PATCH] vault backup: 2024-11-19 21:49:36 --- .../ECE1400/Chapter 17 Exercises.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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