传智播客扫地僧C/C++学习笔记冒泡排序

#include "stdlib.h"
#include "string.h"
#include "stdio.h"


void main()
{

	int i = 0;
	int a[] = { 22, 56, 4, 57, 8, 10 };

	printf("----before-----\n");
	for (	auto i:a)
	{
		printf("%d\n", i);
	}
	int tem = 0;

	//排序
	//外层内层
	for (size_t i = 0; i < 6; i++)
	{
		for (size_t j = i+1; j < 6; j++)
		{
			if (a[i] < a[j] )
			{
				tem = a[i];
				a[i] = a[j];
				a[j] = tem;
			}
		}
	}

	printf("----after-----\n");

	for (auto i : a)
	{
		printf("%d\n", i);
	}






}

猜你喜欢

转载自blog.csdn.net/moonlightpeng/article/details/85330514