123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

   Computer Science / IT
   Electronics
   Electrical
   Mechanical
   Chemical
   Civil

   CAT / MBA

   GMAT / Foreign MBA
Latest Jobs

Engineering Jobs / Technical Jobs
Management Jobs

Sitemap
Terms of use

Displaying  Source Code(s)  
 

 
Selection Sort

--------------------------------------------------------------------------------

Description : Selection Sort that shows every pass

Code :
import java.io.*;

class select

{
public static void main(String args[])throws IOException
{
int[] array = new int[100];
int max = 9;
int low , temp;
int a = 0;

try
{
BufferedReader keyb = new BufferedReader (new
InputStreamReader(System.in));
System.out.print("Enter max number to be sort:");
max = Integer.parseInt(keyb.readLine());
for (int x = 0 ; x < max ; x++)
{
System.out.print("Enter number:");
array[x] = Integer.parseInt(keyb.readLine());
}
for (int m = 0 ; m < max ; m++)
{

System.out.print(array[m] + " ");
}
System.out.print("<BR>);
//for (int a = max - 1; a > 0; a--)
{

for( int b = 0 ; b < max ; b++)
{
low = array[b];
for (int c = b ; c < max ; c++)
{
if (array[c] < low)
{
low = array[c];
//System.out.print("<" + b + "><" + c + "><" + low + "><BR>);
}
else
{
// System.out.print("<" + b + "><" + c + "><" + low + "><BR>);
}


for (int d = b ; d < max ; d++)
{
if (array[d] == low)
{
temp = array[b];
array[b] = array[d];
array[d] = temp;
//System.out.print("*" + c + "*");
}
}
}

System.out.print("<BR>);
for (int m = 0 ; m < max ; m++)
{

System.out.print(array[m] + " ");
}

System.out.print("<BR>);


}

}
}
catch (IOException e)
{
System.out.println("System Error");
}
catch (NumberFormatException er)
{
System.out.println("Kindly enter a number");
}
 

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved © copyright 123ENG