标签:turn swap clu style 冒泡 main c语言实现 冒泡排序 else
C语言实现:
冒泡排序:
#include <stdio.h> void swap(int num[], int i, int j); void Bubble(int num[], int n, int ascending); //vc6认不到bool int main() { int i, numbers[10]; for (i = 0; i < 10; i++) { scanf("%d", &numbers[i]); } Bubble(numbers, 10, 0); for (i = 0; i < 10; i++) { printf("%d ", numbers[i]); } printf("\n"); return 0; } void Bubble(int num[], int n, int ascending) { int i, j; for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { if (ascending) { if (num[i] > num[j]) swap(num, i, j); } else { if (num[i] < num[j]) swap(num, i, j); } } } } void swap(int num[], int i, int j) { int temp = num[i]; num[i] = num[j]; num[j] = temp; }
标签:turn swap clu style 冒泡 main c语言实现 冒泡排序 else
原文地址:http://www.cnblogs.com/quanxi/p/6700808.html