Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
package sorting;
public class selection_sort
{
    public static void main(String[] args) 
    {  
    int x[] = { 23 , 24 , 87 , 12 , 2 , 1 } ;  
    int i , j ;
    
int l ;
int c ;

for ( i =0 ; i<=4  ; i++ )   
{
    
for ( j = i ; j<=4 ; j++ )     
{
     
   if (x[i] > x[j+1] )
   {
   c= x[i];
   x[i]=x[j+1] ;       
    x[j+1] = c ;
   
   } 
}

    System.out.println();
System.out.println(" after stage " + (i+1) + " array is ") ;
    System.out.println();
        
for ( int k =0 ; k<=5 ; k++)
{
    System.out.print(x[k] + "   ");
}

    System.out.println();
    }
     
System.out.println(" FINALLY SORTED ARRAY IS : ");
for ( int k =0 ; k<=5 ; k++)
{
    System.out.print(x[k] + "   ");
}
    }
   
}



Is this a program of selection sort ?

What I have tried:

I have run this on netbeans IDE .
Posted
Updated 11-May-17 1:33am

Nope, that is bubble sort[^].
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900