vault backup: 2024-11-19 21:49:36
This commit is contained in:
parent
7661f4b835
commit
b677e73bbe
@ -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
|
> **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;
|
||||||
|
}
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user