Insertion into a sorted table

Write a procedure that, supposing that all the positions of @v@, except
maybe the last one, are in non-decreasing order, leaves @v@ totally in
non-decreasing order.

For instance, if @v@ is ⟨2, 4, 7, 7, 8, 9, 5⟩, it must become
⟨2, 4, 5, 7, 7, 8, 9⟩.

Interface

+-------:+:-------------------------------------------+
| C++    |     void insert(vector<double>& v);        |
+--------+--------------------------------------------+
| C      |     void insert(int n, double v[n]);       |
+--------+--------------------------------------------+
| Java   |     public static void insert(double[] v); |
+--------+--------------------------------------------+
| Python |     insert(v)  # returns None              |
+--------+--------------------------------------------+
| MyPy   |     insert(v: list[float]) -> None         |
+--------+--------------------------------------------+

Precondition

We have |v| ≥ 1. Moreover, the positions 0 to |v|−2 of @v@ are in
non-decreasing order.

Observation

You only need to submit the required procedure; your main program will
be ignored.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T12:16:29.532Z

© Jutge.org, 2006–2026.
https://jutge.org
