• 修改选择排序 Exercise07_20


     1 import java.util.Scanner;
     2 /**
     3  * @author 冰樱梦
     4  * 时间:2018年12月
     5  * 题目:修改选择排序
     6  *
     7  */
     8 public class Exercise07_20 {
     9     public static void main(String[] args){
    10         double[] list=new double[10];
    11         Scanner input=new Scanner(System.in);
    12         System.out.println("输入10个double类型的数: ");
    13         for(int i=0;i<list.length;i++){
    14             list[i]=input.nextDouble();
    15         }
    16         SelectionSort(list);
    17     }
    18     
    19     
    20     
    21     /**
    22      * @param 选择排序,原来是找到最小值放到第一位,而后修改程序为找到最大值,放到最后一位
    23      */
    24     public static void SelectionSort(double list[]){
    25         for(int i=list.length-1;i>0;i--){
    26             double currentMax=list[i];
    27             int currentMaxIndex=i;
    28             for(int j=i-1;j>=0;j--){
    29                 if(currentMax<list[j]){
    30                     currentMax=list[j];
    31                     currentMaxIndex=j;
    32                 }
    33             }
    34             if(currentMaxIndex != i){
    35                 list[currentMaxIndex]=list[i];
    36                 list[i]=currentMax;
    37             }
    38         }
    39         for(double a:list){
    40             System.out.print(a+" ");
    41         }
    42     }
    43 }
  • 相关阅读:
    刘汝佳,竖式问题
    二叉树
    sort
    hash
    贪心算法
    FFT,NTT 专题
    hdu 5861 Road 两棵线段树
    hdu 5862 Counting Intersections
    hdu 5833 Zhu and 772002 ccpc网络赛 高斯消元法
    hdu 5800 To My Girlfriend + dp
  • 原文地址:https://www.cnblogs.com/cherrydream/p/10174154.html
Copyright © 2020-2023  润新知