zoukankan      html  css  js  c++  java
  • 选择排序(java版)

     1 public class SelectSortTest {
     2     public static void selectSort(int[] source) {
     3         for (int i = 0; i < source.length; i++) {
     4             for (int j = i + 1; j < source.length; j++) {
     5                 if (source[i] > source[j]) {
     6                     swap(source, i, j);
     7                 }
     8             }
     9         }
    10     }
    11     //private 完成交换功能的子函数
    12     private static void swap(int[] source, int x, int y) {
    13         int temp = source[x];
    14         source[x] = source[y];
    15         source[y] = temp;
    16     }
    17     //在main中测试
    18     public static void main(String[] args) {
    19         int[] a = {4, 2, 1, 6, 3, 6, 0, -5, 1, 1};
    20         
    21         selectSort(a);
    22         
    23         for (int i = 0; i < a.length; i++) {
    24             System.out.printf("%d ", a[i]);
    25         }
    26     }
    27 }
  • 相关阅读:
    点子
    点子
    ruby crawler Anemone
    创业站
    我友网 没前途
    创意
    电商站
    尿布
    创意
    青番茄好项目
  • 原文地址:https://www.cnblogs.com/happyhacking/p/4350376.html
Copyright © 2011-2022 走看看