Insert at End of Linked List
Easyjavapythonccppjavascript
Given a linked list and a value X, add a new node containing X at the end and print the resulting list.
Input Format
The first line contains an integer N. The second line contains N space-separated integers (empty if N is 0). The third line contains the integer X.
Output Format
Print the updated list from head to tail, separated by single spaces.
Example 1
Input
3 10 20 30 40
Output
10 20 30 40
Explanation: The new node is attached after the current last node.
- 0 <= N <= 100000
- -1000000000 <= value, X <= 1000000000