| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11939 | Insertion sort |
|
| 11254 | Array Sorting |
|
Description
Please implement insertion sort algorithm to sort a sequence of number in ascending order, and show the sequence of number after each insert phase.
insertion sort (wiki): https://en.wikipedia.org/wiki/Insertion_sort
Input
There are 2 lines input.
The first line contains a integer n, indicating the total number of integers would be sorted. (n <= 1000)
The second line consists of the integers being sorted.
Output
Show the sequence of number after each insert phase.
If the input has n numbers, the output would have n-1 lines.
note: print a space before each number, and print '\n' in the end of each line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given a two-dimensional array of size R x 5 (1 < R < 100).
We want to sort the two dimensional array according to each column.
For example:
|
5 |
1 |
3 |
11 |
25 |
|
45 |
82 |
97 |
73 |
63 |
|
13 |
47 |
34 |
26 |
14 |
After sorted
|
5 |
1 |
3 |
11 |
14 |
|
13 |
47 |
34 |
26 |
25 |
|
45 |
82 |
97 |
73 |
63 |
Note that
1. This problem involves three files.
- function.h: Function definition of sortArray.
- function.c: Function implementation of sortArray.
- main.c: A driver program to test your implementation.
You will be provided with main.c and function.h, and asked to implement function.c.
2. For OJ submission:
Step 1. Submit only your function.c into the submission block. (Please choose c compiler)
Step 2. Check the results and debug your program if necessary.
Hints:
function.h
main.c
Input
The first line has an integer N(1<=N<=5000), which means the number of test cases.
For each case, the first line has an integer R (1<R<100) represent the numbers of rows. The following R lines, each containing 5 integers, specify the elements of the two-dimensional array.
Output
Print out all elements of the sorted array row-by-row.
All of the integers in the same line are separated by a space and there is a '\n' at the end of each line. All of the arrays should be separated by a new line character (\n).