Ordena un Vector R S98018


Statement
 

pdf   zip   main.cc

thehtml

A vector R is a vector that is composed of two parts:

v = x1  ‍ x2  ‍ x3  ‍ x4 … xn  ‍ y1  ‍ y2 ‍ y3 … ym

such that the part x1xn and the part y1ym are ordered strictly in increasing order but ym < x1. Furthermore, we have that n,m > 0. That is, neither part is empty.

We need to implement the function void ordena(vector<int>& v, int pos) with the following specification:

PRE: v is a vector R such that ∣ v ∣ ≥ 3, and pos is the position of y1 in v.

POST: The vector v is sorted.

Observation

You only need to send the function we ask for and the actions and functions that you define yourself. The rest will be ignored.

You cannot use the operation sort from the stl library.

Hint: knowing the position of y1 can help you sort the vector in linear time.

On the other hand, if you use an auxiliary vector to sort you will have a penalty of −5 on manual correction even if you have a green traffic light.

Input

An undetermined number of vectors R with the following format: an integer indicating their size, then the vector R and finally the position where y1 is located. Every vector R has a size greater than or equal to 3.

Output

The sorted vector v.

Sample session
ENTRADA 1:
15
11 12 13 14 15 1 2 3 4 5 6 7 8 9 10
5

SORTIDA 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15



ENTRADA 2:
15
3 4 5 6 7 8 9 10 11 12 13 14 15 1 2
13

SORTIDA 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15



ENTRADA 3:
15
15 1 2 3 4 5 6 7 8 9 10 11 12 13 14
1

SORTIDA 3:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15



ENTRADA 4:
5
12 15 4 7 8
2

SORTIDA 4:
4 7 8 12 15
Information
Author
PRO1
Language
English
Translator
Original language
Catalan
Other languages
Catalan Spanish
Official solutions
C++
User solutions
C++