zoukankan      html  css  js  c++  java
  • 三个排序

    选择排序

     1   void Select(int *a,int n)
     2     {
     3         for (int i = 0; i < n; i++)
     4         {
     5             int lowindex = i;
     6             for (int j = i + 1; j < n; j++)
     7             {
     8                 if (a[j] < a[lowindex])
     9                     lowindex = j;
    10                 swap(&a[i], &a[lowindex]);
    11             }
    12         }
    13     }

    冒泡排序

    1 void Bubblesort(int *a,int n)
    2     {
    3     for(int i=0;i < n; i++)
    4         if(a[j] >a[j+1])
    5             swap(&a[i], &a[lowindex]);
    6     }

    插入排序

     1 void insertsort()
     2     {
     3         int i ,j;
     4         int temp;
     5         for (i = 1; i < n; i++)
     6         {
     7             temp = a[i];
     8             for (j = i; j > 0 && temp < a[j - 1]; j--)
     9             {
    10                 a[j] = a[j - 1];
    11             }
    12             a[j] = temp;
    13         }
    14     }
  • 相关阅读:
    省选测试29
    省选测试28
    省选测试27
    省选测试26
    省选测试25
    最小费用最大流Dinic
    省选测试24
    省选测试23
    省选测试22
    省选测试21
  • 原文地址:https://www.cnblogs.com/RightDear/p/2628757.html
Copyright © 2011-2022 走看看