zoukankan      html  css  js  c++  java
  • 插入排序

    #include <iostream>
    #include <ctime>

    using namespace std;

    void RandomArray(int *arr,int arr_len);
    void Interpolation(int *arr,int arr_len);
    void PrintArray(int *arr,int arr_len);

    int main()
    {
    const static int arr_len = 20;
    int arr[arr_len];

    RandomArray(arr,arr_len);
    PrintArray(arr,arr_len);
    Interpolation(arr,arr_len);

    PrintArray(arr,arr_len);

    return 0;
    }

    void PrintArray( int *arr,int arr_len )
    {
    cout<<"打印内容:"<<endl;
    for (int i=0;i<arr_len;++i)
    {
    cout<<arr[i]<<" ";
    }

    cout<<endl;
    }

    void RandomArray( int *arr,int arr_len )
    {
    srand(time(NULL));

    for (int i=0;i<arr_len;++i)
    {
    arr[i] = rand()%100;
    }

    }

    void Interpolation( int *arr,int arr_len )
    {
    for (int i=1;i<arr_len;++i)
    {
    int tempValue = arr[i];
    int j=i;
    for (;j>0;--j)
    {
    if (tempValue>arr[j-1])
    {
    break;
    }
    else
    {
    arr[j] = arr[j-1];
    }
    }

    arr[j] = tempValue;
    }
    }

    image
  • 相关阅读:
    Debate
    图形算法
    OpenGL Notes
    How to Write an Ethics Paper
    Thesis
    addWindowListener -> WindowAdapter -> windowClosing
    Thesis
    Bootcamp: An error occurred while partitioning the disk
    What Is XML Schema
    What Is XML
  • 原文地址:https://www.cnblogs.com/sharpfeng/p/2673809.html
Copyright © 2011-2022 走看看