#include <stdio.h> #define SIZE 5 void bubbleSort(int *array_a, int array_size); void swap(int *sw1, int * sw2); int main() { int a[SIZE]={3, 6, 1, 9, 2}; int i; printf("original array:\n"); for (i=0; i < SIZE; i++) { printf(" %d", a[i]); } printf("\n"); bubbleSort(a, SIZE); printf("bubble sort array:\n"); for (i=0; i < SIZE; i++) { printf(" %d", a[i]); } printf("\n"); return 0; } void bubbleSort(int *array_a, int array_size) { int j, k; for (j=0; j < SIZE-1; j++) { for (k=0; k < SIZE-1; k++) { if (array_a[k] > array_a[k+1]) { swap(&array_a[k], &array_a[k+1]); } } } } void swap(int *sw1, int * sw2) { int temp; temp = *sw1; *sw1 = *sw2; *sw2 = temp; }[Answer]
original array:
3 6 1 9 2
bubble sort array:
1 2 3 6 9