← Back to Pointers
Question 472
Append Numbers to a Linked List Tail
Append Numbers to a Linked List Tail
Read integers from standard input until the input runs out, appending each value to the TAIL of a singly linked list so the list holds them in the order they arrived. Append — do not prepend and reverse afterwards. Then print the list, the number of nodes, and the sum of all the values. For the input: 5 12 3 the program prints exactly the output shown in Expected Output. Format:List:then, for EVERY node, a space, the value, a space and->, followed by a space andNULLafter the last node (so an empty list would printList: NULL). ThenNodes:with the count andSum:with the total. Free the memory you allocate before the program ends — this question checks for memory leaks.
Expected Output:
List: 5 -> 12 -> 3 -> NULL Nodes: 3 Sum: 20
= 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.