/************************
        BUBBLE SORT
Author:Rhysn    Date:2015
*************************/

#include <stdio.h>
#include <stdlib.h>

typedef int ElemType;

void swap(ElemType *left,ElemType *right){
    ElemType temp = *left;
    *left = *right;
    *right = temp;
}

void BubbleSort(ElemType *array,int num){
    if(num == 1) return;

    ElemType *left = array,*right = array + 1;
    int key = num;
    while(--key){
        if(*left > *right)
            swap(left,right);
        left++;
        right++;
    }
    BubbleSort(array,--num);
}

int main(){
    
    int a[14];

    int *b=a;
    int num = 14;
    srand((unsigned)time(NULL));
    while (num--) *b++ = rand()%10;

    b=a;
    num=14;
    while(num--){
        printf("%d ",*b++ );
    }
    printf("\n");

    BubbleSort(a,14);

    num = 14;
    b=a;
    while(num--){
        printf("%d ",*b++ );
    }
    printf("\n");

    return 0;
}
