/*
2011-9-18
written by qiya
*/
#include <stdio.h>#include <stdlib.h>
#include <time.h>
#define swap(a, b) {a = a^b; b = b^a; a = a^b;}
#define size 20
void bubble_sort(int a[], int n)
{
int i, j;
bool flag = true;
for(i = 0; i < n-1 && flag; i++) {
flag = false;
for(j = n-1; j > i; j--) {
if(a[j] > a[j-1]) {
swap(a[j], a[j-1]);
flag = true;
}
}
}}
void output(int a[], int n)
{
int i;
for(i = 0; i < n; i++)
printf("%d ", a[i]);
printf("\n");}
int main()
{
int i;
int *a = (int *) malloc(size * sizeof(int));
srand(time(NULL));
for(i = 0; i < size; i++)
a[i] = rand()%size;
output(a, size);
bubble_sort(a, size);
output(a, size);}