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
  • 相关阅读:
    树的直径
    POJ3264 Balanced Lineup
    [mock]10月11日
    POJ1062 昂贵的聘礼
    POJ3295 Tautology
    [topcoder]TopographicalImage
    POJ1753 Flip Game
    [leetcode]Copy List with Random Pointer
    [leetcode]Candy
    [leetcode]Gas Station
  • 原文地址:https://www.cnblogs.com/sharpfeng/p/2673809.html
Copyright © 2011-2022 走看看