zoukankan      html  css  js  c++  java
  • 冒泡算法

    include

    using namespace std;
    //Function prototype
    int* selectSort(int ,int);
    void showArray(const int [],int);
    int main()
    {
    int array[] = {7,2,4,5,9,10};
    int size = sizeof(array)/sizeof(array[0]);//求数组的长度
    showArray(array,size);
    selectSort(array,size);
    showArray(array, size);
    cout <<array<< endl;
    return 0;
    }
    int
    selectSort(int p,int size)
    {
    int temp;
    int swap;
    do
    {
    swap = false;
    for (int i = 0; i < (size - 1);i++)
    {
    if (
    (p+i) > *(p +i+ 1))
    {
    temp = *(p+i);
    *(p + i) = *(p + i + 1);
    *(p + i + 1) = temp;
    swap = true;
    }
    }

    } while (swap);
    return p;
    

    }
    void showArray(const int array[], int size)
    {
    for (int count=0;count<size;count++)
    {
    cout << array[count] <<" ";
    }
    cout << endl;
    }

  • 相关阅读:
    本周总结
    本周总结
    第四周自我总结
    结对编程
    第四周自我总结
    第三周自我总结
    本周工作安排及内容
    知识思考
    交作业。。。
    MSF过程模型
  • 原文地址:https://www.cnblogs.com/131415-520/p/11722079.html
Copyright © 2011-2022 走看看