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

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

传智播客扫地僧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);
	}






}

 

相关文章:

  • 2021-10-22
  • 2021-05-20
  • 2021-06-25
  • 2021-05-20
  • 2021-11-02
  • 2021-12-12
猜你喜欢
  • 2021-04-23
  • 2021-06-30
  • 2022-12-23
  • 2021-05-18
  • 2022-12-23
  • 2021-10-01
  • 2021-11-14
相关资源
相似解决方案