示例#1
0
int main()
{
    int arr[] = {7, 2, 0, 1, 8, 3};
    int arr_size = sizeof(arr)/sizeof(int);
    print_arr(arr, arr_size);
    insertion_sort(arr, arr_size);
    insertion_sort_desc(arr, arr_size);
}
示例#2
0
int main(){
	
	int a[6] = {1,2,3,4,5,6};
	int i;

	insertion_sort_desc(a,6);
	for(i=0;i<5;i++)
		assert(a[i] > a[i+1]);

	insertion_sort_asc(a,6);
	for(i=0;i<5;i++)
		assert(a[i] < a[i+1]);

	return 0;
}
示例#3
0
int main(void)
{
	int test_case;
	int T;
	/*
	   The freopen function below opens input.txt file in read only mode, and afterward,
	   the program will read from input.txt file instead of standard(keyboard) input.
	   To test your program, you may save input data in input.txt file,
	   and use freopen function to read from the file when using scanf function.
	   You may remove the comment symbols(//) in the below statement and use it.
	   But before submission, you must remove the freopen function or rewrite comment symbols(//).
	 */
	// freopen("input.txt", "r", stdin);

	/*
	   If you remove the statement below, your program's output may not be rocorded
	   when your program is terminated after the time limit.
	   For safety, please use setbuf(stdout, NULL); statement.
	 */
	setbuf(stdout, NULL);

	scanf("%d", &T);
	for(test_case = 0; test_case < T; test_case++)
	{
		int i;
		scanf("%d", &N);
		
		for(i = 0; i < N; i++) {
			scanf("%d", &data[i]);
		}

		/**********************************
		 * Implement your algorithm here. *
		 **********************************/
		time = 0;
                
                insertion_sort_desc(data, N);
                time = compute(data, N);
		
		// Print the answer to standard output(screen).
		printf("%d\n",time);
		
	}

	return 0;//Your program should return 0 on normal termination.
}