码迷,mamicode.com
首页 > 编程语言 > 详细

冒泡排序

时间:2015-02-12 15:56:54      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

1.冒泡排序

#include "stdafx.h"
#include <stdio.h>
#include <iostream>
//数组长度
#define ARRAY_SIZE 6

//冒泡排序
void BubbleSort(int my_array[])
{
    int temp;
    for(int i=0;i<ARRAY_SIZE-1;i++)
    {
        for(int j=0;j<ARRAY_SIZE-1-i;j++)
        {
            if(my_array[j]>my_array[j+1])
            {
                temp=my_array[j];
                my_array[j]=my_array[j+1];
                my_array[j+1]=temp;

            }
        }
    }

}
int _tmain(int argc, _TCHAR* argv[])
{
    int my_array[ARRAY_SIZE]={8,3,2,5,1,7};
    BubbleSort(my_array);

    for(int i=0;i<ARRAY_SIZE-1;i++)
    {
        std::cout<<" "<<my_array[i];
    }
    std::cout<<std::endl;
    system("pause");
    return 0;
}

 

冒泡排序

标签:

原文地址:http://www.cnblogs.com/ike_li/p/4287878.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!