[算法]冒泡排序

时间复杂度O(n^2)
基本思想:类似于冒气泡,将最大的冒到最上面。有两个指针,一个指着当前需要排序的序列,一个指着最后,然后慢慢往上冒。

#include 
#include 
#include 
#include 
using namespace std;

void swap(int &a,int &b)
{
    int temp=a;
    a=b;
    b=temp;
}
void bubbleSort(int a[],int size)
{
    for(int i=0;i=i+1;j--)
        {
            if(a[j]

[算法]冒泡排序_第1张图片

你可能感兴趣的:([算法]冒泡排序)