Hi,
I tried to write the source code myself but there're tons of errors. And even if i can compile i bet it doesn't work. I need a solution. I need to study. Pls help. Thnx. Note that i need to use recursive techniques.
THis is what i have just to prove that i really tried myself:
Code:
/* Quicksort */
#include <stdio.h>
#define SIZE 10
void quicksort( int array[], int starting, int ending );
void partition( int array, int arraySize, int starting, int ending );
int main()
{
int array[ SIZE ] = { 37, 2, 6, 4, 89, 8, 10, 12, 68, 45 };
int i;
quicksort( array, 0, 9 );
for ( i = 0; i < SIZE; i++ )
printf( "%d ", array[ i ] );
printf( "\n" );
getch();
return 0;
}
void partition( int array, int arraySize, int starting, int ending )
{
int temp;
int i, end = 0;
int rightmost = ending;
int ele = starting;
int swapsMade = 0;
int leftmost;
while ( end != 1 ) {
for ( i = rightmost; i >= 0; i-- ) {
if ( array[ i ] < array[ ele ] ) {
temp = array[ ele ];
array[ ele ] = array[ i ];
array[ i ] = temp;
temp = ele;
ele = i;
leftmost = temp;
swapsMade++;
break;
}
}
for ( i = leftmost; i < arraySize; i++ ) {
if ( array[ i ] > array[ ele ] ) {
temp = array[ ele ];
array[ ele ] = array[ i ];
array[ i ] = temp;
temp = ele;
ele = i;
rightmost = temp;
swapsMade++;
break;
}
}
if ( swapsMade == 0 )
end = 1;
}
}
void quicksort( int array[], int starting, int ending )
{
int i;
int inOrder = 0;
for ( i = 0; i < SIZE - 2; i++ )
if ( array[ i ] < array[ i + 1 ] )
inOrder = 1;
if ( inOrder != 1 )
partition( array, SIZE, starting, ending );
}