Java - Selection Sort Algorithm

后端 未结 17 1610
我在风中等你
我在风中等你 2020-12-17 04:26

I have some questions about selection sort.I\'m a little bit confused.

 int [] arr = {5,4,3,2,1}; // This is my array
    int min = 0;

    for(int i = 0;i&l         


        
17条回答
  •  北海茫月
    2020-12-17 04:46

    public class Selectionsort{

    public static int arr[]; public static int y;

    public static void main( String args[] ){

    System.out.println("Enter number of element you want to enter for sorting");

    int nofele= Integer.parseInt(args[0]);
    
    System.out.println("Enter number of element entered for sorting is "+ "\n" +nofele);
    
    arr = new int[nofele];
    
    System.out.println("Entered array is");
    
    for(int i=1,j=0;i<=nofele;i++,j++){
    
    arr[j]=Integer.parseInt(args[i]);
    
      System.out.println(arr[j]);
    
    }
    
    System.out.println("Sorted array for selection sort is ");
    
    for(int k=0;k=2;l--,b++){
    
        if(arr[k]>arr[k+b]){
    
    
    
         int temp=arr[k];
    
          arr[k]=arr[k+b];
    
          arr[k+b] = temp;
    
    
        }     
    
      }
    
       System.out.println(arr[k]);
    
    }
    
       System.out.println(arr[nofele-1]);
    

    }

    }

提交回复
热议问题