Hi,
I am writing a program which performs selection sort. but when i run my program it says there are errors generated and will be closed by windows. I am using DevC++. Then i tried the built-in debugger and it's something about segmentation fault. Then i tried running on Borland C++ builder and it says something about memory access violation. Lastly i tried running with Pacific MS-DOS C compiler and it ran, only seem to left out the number 3 which is in the array and added the number '-900' at the beginning of the sentence. Pls tell me what's wrong and how to fix it. Thnx.
Code:/* selection sort */ #include <stdio.h> void selSort( int array[], int arraySize ); int main() { int array[ 10 ] = { 3, 6, 1, 2, 4, 7, 5, 9, 10, 8 }; int i; printf( "Original array of numbers: \n " ); for ( i = 0; i < 10; i++ ) printf( "%d ", array[ i ] ); printf( "\n" ); printf( "Array after sorted by 'selection-sort': \n" ); selSort( array, 10 ); printf( "\n" ); return 0; } void selSort( int array[], int arraySize ) { int min, temp, i; int swapPos; for( i = 0; i < arraySize; i++ ) if ( min > array[ i ] ) { min = array[ i ]; swapPos = i; } if ( arraySize != 1 ) { temp = array[ 0 ]; array[ 0 ] = min; array[ swapPos ] = temp; printf( "%d ", array[ 0 ] ); selSort( &array[ 1 ], arraySize - 1 ); } }



LinkBack URL
About LinkBacks



)