U E D R , A S I H C RSS

몸짱프로젝트/Bubble Sort

C version


~cpp 
#include <stdio.h>

int * sort(int aArr[]);
void swap(int & aVal1, int & aVal2);
const int SIZE = 10;
void main()
{
	int arr[SIZE] = {1,13,11, 22,6,4,72,11,9,10};
	int * p_arr = sort(arr);
	for ( int i = 0 ; i < SIZE ; i++, p_arr++)
		printf("%d\n", *p_arr);
}

int * sort(int aArr[])
{
	for ( int i = 0 ; i < SIZE ; i++)
		for ( int j = 0 ; j < SIZE ; j++)
			if ( aArr[i] < aArr[j] )
				swap(aArr[i], aArr[j]);
	return aArr;
}

void swap(int & aVal1, int & aVal2)
{
	int temp = aVal1;
	aVal1 = aVal2;
	aVal2 = temp;
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.2872 sec