Tuesday, March 17, 2009

C Program Selection Sort

// Program for Selection Sort

#include <iostream.h>
#include <conio.h>



//----------------------------------------------------------------------

void Selectionsort ( int array[] , int UB )
{
for ( int i = 0 ; i <= UB ; i++ )
for ( int j=i+1 ; j<=UB ; j++ )
{
if ( array [i] > array [j] )
{
int temp = array [i] ;
array [i] = array[j] ;
array [j] = temp ;

}
}
}


void Showarray ( int array[] , int UB )
{
gotoxy ( 1,2 ) ;
cout << "\n" ;

for ( int i = 0 ; i <= UB ; i++ )
{
cout << array [i] << endl ;
}

}

//----------------------------------------------------------------------

void main ()
{
clrscr ();

int array [10] = { 42 , 23 , 74 , 11 , 65 , 58 , 94 , 36 , 99 , 87 };

Selectionsort ( array , 9 ) ;

Showarray ( array , 9 ) ;

getch ();

}

No comments:

Post a Comment