zoukankan      html  css  js  c++  java
  • 排序之选择排序

      1、直接选择排序(Straight Select Sorting) 也是一种简单的排序方法,它的基本思想是:第一次从R[0]~R[n-1]中选取最小值,与R[0]交换,第二次从R[1]~R[n-1]中选取最小值,与R[1]交换,....,第i次从R[i-1]~R[n-1]中选取最小值,与R[i-1]交换,.....,第n-1次从R[n-2]~R[n-1]中选取最小值,与R[n-2]交换,总共通过n-1次,得到一个按排序码从小到大排列的有序序列。

     1 #include<iostream>
     2 using namespace std;
     3 
     4 void  Selectsort(int a[], int n)
     5 {
     6     int i, j, temp;
     7     for (i = 0; i < n; i++)
     8     {
     9         temp = a[i];
    10         for (j = i+1; j < n; j++)
    11         {
    12             if (a[j] < temp)
    13             {
    14                 temp = a[j];
    15                 a[j] = a[i];
    16                 a[i] = temp;
    17             }
    18         }
    19         
    20     }
    21 }
    22 int main()
    23 {
    24     int a[]={9, 6, 3, 4, 5, 7};
    25     Selectsort(a,6);
    26     for (int i = 0; i < 6; i++)
    27         cout << a[i] << endl;
    28     return 0;
    29 }

     

  • 相关阅读:
    Hit Event 击中碰撞
    基于ReentrantLock通知唤醒的生产消费模式
    spring 源码构建
    读写分离、分库、分表
    python 反射的使用
    基础算法
    git 命令使用
    java设计模式应用
    linux 中python的使用
    linux命令
  • 原文地址:https://www.cnblogs.com/wsw-seu/p/7654748.html
Copyright © 2011-2022 走看看