897 - EECS_I2P(I)2015_Chen_Lab_10(mid2_review) Scoreboard

Time

2015/12/16 08:20:00 2015/12/16 09:50:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10878 Array sort_row

10878 - Array sort_row   

Description

Given two dimensional array of size M x N(1 < M,N < 10).

We want to sort separately for each row of the two dimensional array value

For example:

5

1

3

11

25

45

82

97

73

63

13

47

34

26

14

After sorted

1

3

5

11

13

45

63

73

82

97

13

14

26

34

47

Submit only your function.c into the submission block. (Please choose C compiler) 

The bubble sort algorithm:

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

for (i = 0; i < n; i++) {

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

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

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

      }

   }

}

 

main.c

#include <stdio.h>

#include "function.h"

 

int main()

{

    int M,N;

    int i,j;

    scanf("%d%d", &M, &N);

    int array[M][N];

    for(i = 0; i < M; i++)

                for(j = 0; j < N; j++)

                        scanf("%d", &array[i][j]);

    sortArray( M, N, array);

    printResult( M, N, array);

    return 0;

}

 

function.h

void swap(int *a, int *b);

void sortArray(int M, int N, int (*array)[N]);

void printResult(int M, int N, int (*array)[N]);

Input

The first line is two dimensional array size M and N.(1 <M,N <10)

The other line are value of array to be sorted.

 

Output

Each line shows output of sorted array.

All of the integers in the same line are separated by a space, and there is a '\n' at the end of each line.

Sample Input  Download

Sample Output  Download

Partial Judge Code

10878.c

Partial Judge Header

10878.h

Tags




Discuss