11752 - My Insertion Sort   

Description

In out class, HT Chen introduced a way to implement a qsort-like mysort using bubble sort. 

To make you more clearly to the machism, you are asked to implement a qsort-like mysort using insertion sort.

The main function has already provided for you, what you have to do is just implement the mysort function.

For more specific, you just need to fill the following blank:

#include <stdio.h>
#include <stdlib.h>

int compare(const void* a, const void* b)
{
    // compare a with b
}


void assign(char* x, char* y, size_t size) {
   // assign y to x
}

void mysort(void* arr, size_t count, size_t size, int (*cmp) (const void*, const void*))
{
    // do sorting!!!
}

 

The pseudo code below would be helpful if you want to know how the insertion sort works.

i ← 1
while i < length(A)
    j ← i
    while j > 0 and A[j-1] > A[j]
        swap A[j] and A[j-1]
        j ← j - 1
    end while
    i ← i + 1
end while

 

Input

There are 2 lines input.

The first line contains a integer, indicating the total number of integers would be sorted.

The second line consists of the integers being sorted.

Output

The integers have been sorted.

Please notice that the sequence has to be in ascending order.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11752.c

Partial Judge Header

11752.h

Tags




Discuss