12103 - Array Sorting   

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 row.

For example:

5

1

3

11

25

45

82

97

73

63

13

47

34

26

14

After sorted

1

3

5

11

25

45

63

73

82

97

13

14

26

34

47

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 : bubble sort algorithm

/* Using bubble sort to rearrange an array A[n] */

for (i = n; i > 0; i--) {

   for (j = 1; j < i; j++) {

      if (A[j-1] > A[j]) {

         /* swap A[j-1] A[j] */

      }

   }

}

 

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).

Sample Input  Download

Sample Output  Download

Partial Judge Code

12103.c

Partial Judge Header

12103.h

Tags




Discuss