← Back to Pointers
Question 469
Sorted Insert Into a Linked List
Sorted Insert Into a Linked List
Build a singly linked list that is kept in ascending order the whole time you are filling it. Read an integernfrom standard input, then readnmore integers. Insert each value into the list at its correct sorted position as you read it — do not load the values into an array and sort them, and do not sort the list at the end. Equal values may sit in either order. For the input: 5 8 3 9 1 5 the program prints exactly the output shown in Expected Output. Format: the first line starts withSorted:, then for EVERY node a space, the value, a space and->, and after the last node a space andNULL. The second line isCount:followed by the number of nodes. Free the memory you allocate before the program ends — this question checks for memory leaks.
Expected Output:
Sorted: 1 -> 3 -> 5 -> 8 -> 9 -> NULL Count: 5
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Pointers
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (p, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.