-->
当前位置:首页 > 题库

PROGRAMMING:K-round insertion sort

Luz5年前 (2021-05-10)题库473
Last time you helped JZK answer ZWG's question, ZWG thought JZK couldn't know how to do it, so he decided to ask him another question.
Give you n numbers, output the N numbers after K rounds of insertion sorting results( From small to large)
Insertion sorting is the most simple and intuitive algorithm. The basic idea is to select the smallest (or largest) element from the data elements to be sorted as the first element every time until all elements are arranged. When the k-round insertion sorting has been completed, the first k digits of the sequence must be ordered.
###Input format:
Input n and K (1 ≤ K < n ≤ 100) in line 1, and N integers to be sorted in line 2, separated by spaces.
###Output format:
Output the middle result sequence after the k-th scan of insertion sort method in one row, and the numbers are separated by spaces, but there must be no extra spaces at the end.
###Input example:
```in
6 3
6 2 5 3 1 4
```
###Output example:
```out
2 5 6 3 1 4
```







answer:If there is no answer, please comment