Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why doesnt my array sort work?

Status
Not open for further replies.

javaguy1

Programmer
May 14, 2003
136
US
can anyone see the problem with my code? it doesn't sort the array.

void ArrayStuff2::sort(int array[], int size )
{
int j;
int temp;

for( int i = 0; i < size - 1; i++ )
{
j = i;
for( int k = i + 1; k < size; k++ )
{
if( array[ k ] < array[ i ] )
j = k;
temp = array[ i ];
array[ i ] = array [ j ];
array[ j ] = temp;
}
}

} // end sort( )
 
never mind, i figured it out

void ArrayStuff2::sort(int array[], int size )
{
int j;
int temp;

for( int i = 0; i < size - 1; i++ )
{
j = i;
for( int k = i + 1; k < size; k++ )
{
if( array[ k ] < array[ i ] )
{
j = k;
temp = array[ i ];
array[ i ] = array [ j ];
array[ j ] = temp;
}
}
}

} // end sort( )



one down one to go
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top