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;
}

运行结果:

 

相关文章:

  • 2021-10-30
  • 2022-01-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
  • 2021-11-14
  • 2021-10-22
猜你喜欢
  • 2021-07-11
  • 2022-12-23
  • 2021-12-12
  • 2021-06-04
  • 2022-01-12
  • 2021-08-31
相关资源
相似解决方案