首页 > 其他分享 >SelectSortDoWhile

SelectSortDoWhile

时间:2022-11-18 01:11:45浏览次数:41  
标签:tmp arr SelectSortDoWhile min int array define

package com.challenger;

import com.challenger.Util;

public class SelectSortDoWhile
{

    public static void main(String[] args)
    {
        //define array
        int[] arr={5,8,2,3,7,4,10,6,9,1};
        //define i as array loop index
        int i;
        //define min as minium index
        int min;
        //define j as each loop to use for compare number
        int j;
        //define temporary number for exchange
        int tmp;

        i=1;
        do
        {
            min=i;
            j=min+1;
            do
            {
                //j-1 and min-1 both represent j and min in array index
                if(arr[j-1]<arr[min-1])
                {
                    min=j;
                }
                j++;
            }
            while(j<=arr.length);

            tmp=arr[i-1];
            arr[i-1]=arr[min-1];
            arr[min-1]=tmp;

            i++;
        }
        while(i<=arr.length-1);


        Util.printArray(arr);
    }
}

标签:tmp,arr,SelectSortDoWhile,min,int,array,define
From: https://www.cnblogs.com/lsjava/p/16901928.html

相关文章