Advertisement
Sampywise

Selection Sort

Jul 11th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1.  
  2. public class SelectionSort {
  3.     public static void main(String[] args) {
  4.        
  5.         int array[] = {30,2,46,8,64,88,59,86,-3,29};
  6.        
  7.         System.out.println("Orriginal Array:");
  8.        
  9.         for(int k = 0; k < 10; k++) {
  10.             System.out.println(array[k]);
  11.         }
  12.        
  13.         int temp = -1;
  14.        
  15.         for(int i = 0; i < 10; i++) {
  16.             for(int j = i; j < 10; j++) {
  17.                 if(array[j] < array[i]) {
  18.                     temp = array[j];
  19.                     array[j] = array[i];
  20.                     array[i] = temp;
  21.                 }
  22.             }
  23.         }
  24.        
  25.         System.out.println("Sorted Array:");
  26.        
  27.         for(int l = 0; l < 10; l++) {
  28.             System.out.println(array[l]);
  29.         }
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement