zoukankan      html  css  js  c++  java
  • 8)排序③排序算法之插入排序[1]直接插入排序

     1 #include<iostream>
     2 using namespace std;
     3 
     4 int direct_sort(int n,int array[100]){//直接插入排序
     5     register int  i,temp;
     6     for(i=1;i<n;i++){
     7         temp=array[i];
     8         int j=i-1;
     9         while(array[j]>temp){
    10             array[j+1]=array[j];
    11             j--;
    12         }
    13         array[j+1]=temp;
    14     }
    15     return 0;
    16 }
    17 
    18 int print(int n,int array[100]){
    19     int i;
    20     for(i=0;i<n;i++){
    21         cout<<array[i]<<" ";
    22     }
    23     cout<<endl;
    24     return 0;
    25 }
    26 int main()
    27 {
    28     int array[10]={5,7,8,2,3,5,4,3,2,1};
    29     direct_sort(10,array);
    30     print(10,array);
    31     return 0;
    32 }
  • 相关阅读:
    jQuery标签操作
    Bootstrap和Font Awesome
    jQuery拾遗
    Bootstrap笔记
    软件测试
    Day01 第一个Python程序
    cd指令
    ls命令
    type命令
    每天一个Linux指令
  • 原文地址:https://www.cnblogs.com/minmsy/p/4963297.html
Copyright © 2011-2022 走看看