冒泡算法 刚看的 求指教

#include <stdio.h>
//#include <window.h>
#define NUMBER_COUNT 10	//改变该数字改变输入的变量数量 
#define NUMER_PER_LINE 5	//改变该数字改变每行显示的数字数量 

void printf_numbers(int* _display);
void sort_bubble(int* _value);

int main(int argc,char* argv)
{
	int value[NUMBER_COUNT];
	int i ;
	for(i = 0;i < NUMBER_COUNT;i++)
	{
		printf("Please Enter the number of value[%d] :",i);
		scanf("%d", &value[i]);
		printf("\n");
	}
	printf("\nBefore Sort");
	printf_numbers(value);
	sort_bubble(value);
	printf("\nAfter Sort");
	printf_numbers(value);
	printf("\n");
	system("pause");
}

void sort_bubble(int* _value)
{
	int i,j,k;
	for(i = 0;i<NUMBER_COUNT;i++)
		for(j = i;j<NUMBER_COUNT;j++)
			if(_value[i]>_value[j])
			{
				k = _value[i];
				_value[i] = _value[j];
				_value[j] = k;
			}
			
}

void printf_numbers(int* _display)
{
	int i;
	for(i = 0; i<NUMBER_COUNT;i++)
	{
		if((i%NUMER_PER_LINE)==0)
			printf("\n");
		printf("%4d\t",_display[i]);
	}
}

你可能感兴趣的:(c,算法,排序,冒泡)