C++-冒泡法排序

1.代码如下:

#include "stdafx.h"
#include <iostream>
using namespace std;
void BubbleSOrt(int *values,int length)
{
    int temp=0;
    for(int i=length-1;i>0;i--)
    {
        for(int j=0;j<i;j++)
        {
            if(*(values+j)>*(values+j+1))
            {
                temp=*(values+j);
                *(values+j)=*(values+j+1);
                *(values+j+1)=temp;
            }
        }
    }
}

int _tmain(int argc, _TCHAR* argv[])
{
    int values[]={14,5,8,20,13,11};
    BubbleSOrt(values,6);
    for(int i=0;i<6;i++)
    {
        cout<<*(values+i)<<endl;
     }
    return 0;
}

运行结果:

 

posted @ 2019-07-15 19:52  一串字符串  阅读(657)  评论(0编辑  收藏  举报