C 冒泡排序原理示范

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//  visual studio 2012 
// C 冒泡排序原理示范

#include "stdafx.h"
#include "iostream"
#include "stdio.h"

//static int test_array[] = {1,2,3,4,5,6};
static int test_array[] = {6,5,4,3,2,1};

void cout_data(void)
{
for (int i =0; i < 6; i++){
if (i < 5){
std::cout << test_array[i];
}
else{
std::cout << test_array[i] << std::endl;
}
}
}

int _tmain(int argc, _TCHAR* argv[])
{
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 5-i ;j++){
//if (test_array[j] < test_array[j+1]){
if (test_array[j] > test_array[j+1]){
int temp = 0;
temp = test_array[j];
test_array [j] = test_array[j+1];
test_array[j+1] = temp;
}
cout_data();
}
std::cout << "i = " << i << std::endl;
}
while (1);
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值