125. Insert at the End
Foundation1000 ms256 MBSolved by 0%
Build the list, read a value k, append a new node holding k at the end,
and print the resulting list.
Appending needs the LAST node, which means walking to it first.
Constraints - `0 ≤ n ≤ 100000` - `-1000000 ≤ value, k ≤ 1000000`
Input
The first line contains an integer n, the number of nodes.
The second line contains n space-separated integers — the node values from head to tail.
The starter code builds the list for you; work on the nodes, not the array.
The third line contains the value to append.
Output
Print the resulting list from head to tail on ONE line, separated by single spaces, or Empty if no nodes remain.
Input3
1 2 3
4
Output1 2 3 4
Noteappends to an existing list
Input0
5
Output5
Noteappends to an empty list, where head itself must be set
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution