Rita li

You give me a future, I love you the whole once

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
#include <iostream>
using namespace std;
void mSort(int *arr, int iLen)
{
    int i, j, k, tmp;
    for(i = 0, j = 0; i < iLen; i++)
    {
        if (arr[i] < 0)
        {
            tmp = arr[i];
            for(k = i; k > j; k--)
                arr[k] = arr[k - 1];
            arr[j++] = tmp;
        }
    }
}

int main()
{
    int arr[] = {1,7,-5,9,-12,15};
   // int iLen = sizeof(arr) / sizeof(int);
    int i;
    int iLen = 6;
    cout<<"输入"<<iLen<<"个数"<<endl;
    for(i = 0; i < iLen; i++)
        cin>>arr[i];
    cout << "排序前数组为: " << endl;
    for(i = 0; i < iLen; i++)
        cout << arr[i] << " ";
    cout << endl

    mSort(arr, iLen);

    cout << "排序后数组为: " << endl;
    for(i = 0; i < iLen; i++)
        cout << arr[i] << " ";
    cout << endl

   // system("PAUSE");
    return 0;
}

 

posted on 2014-06-03 11:13  Rita li  阅读(1161)  评论(0编辑  收藏  举报