数组做函数参数的退化问题

冒泡排序

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

void printArray(int* a)
{
	for (size_t i = 0; i < 6; i++)
	{
		printf("%d\n", a[i]);
	}

}

//  -----------(int a[])
void sortAarry(int* a)
{
	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;
			}
		}
	}

}

void main()
{

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

	printf("----before-----\n");
	printArray(a);
	//排序
	//外层内层
	sortAarry(a);

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

}

猜你喜欢

转载自blog.csdn.net/moonlightpeng/article/details/85330569
今日推荐