头文件Sort.h
#include<stdio.h> void doublebubble(int *L, int n); void swap(int *a, int *b);
函数实现DoubleBubble.c
#include"Sort.h" void swap(int *a,int *b) { int temp; temp = *a; *a = *b; *b = temp; } void doublebubble(int *L,int n) { int low = 0, high = n - 1; while (low < high) { for (int i = 0; i < high; i++) if (L[i] > L[i + 1]) { swap(&L[i], &L[i + 1]); } high--; for (int j = high; j > low; j--) if (L[j - 1] > L[j]) { swap(&L[j], &L[j - 1]); } low++; } }
测试文件Main.c#include"Sort.h" int main() { int i; int arr[10] = { 5,2,1,6,3,8,9,4,7,10 }; doublebubble(&arr, 10); for (i = 0; i < 10; i++) { printf("%d ", arr[i]); } }