zoukankan      html  css  js  c++  java
  • insertSort

     1 static void insertSort2(int* arr, int n) {
     2     int j, temp;
     3     for(int i = 1; i < n; i++) {
     4         temp = arr[i];
     5         for(j = i - 1; j >= 0; j--) {
     6             if(temp < arr[j])
     7                 arr[j + 1] = arr[j];
     8         }
     9         arr[j + 1] = temp;
    10     }
    11 }
     1  #include <stdio.h>
     2  
     3 static void insertSort2(int *arr, int n) {
     4     int i, k, j, temp;
     5     for( i = 1; i < n; i++) {
     6         temp = arr[i];
     7         for(j = i - 1; j >= 0 && temp < arr[j]; j--) {
     8             arr[j + 1] = arr[j];
     9         }
    10         arr[j + 1] = temp;
    11     }
    12     for (k=0; k<n; k++){
    13         printf("%d ", arr[k]);
    14     }
    15     
    16 }
    17 int main(){
    18     int arr[]={1,1,2,1,3,2,4,5,6,8,9,10};
    19     insertSort2(arr, 12);
    20     return 0;
    21 }
  • 相关阅读:
    递归
    匿名函数
    迭代器、可迭代对象、生成器
    日期
    大文件读写
    面向对象
    魔术方法
    进程与线程
    numpy常用函数
    shell编程
  • 原文地址:https://www.cnblogs.com/micoblog/p/13665670.html
Copyright © 2011-2022 走看看