No older revisions available
No older revisions available
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;
}