Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "genlib.h"
- #include "simpio.h"
- #define n 10
- void getArray(int a[]);
- void bubbleSort(int a[]);
- bool isordered(int a[]);
- void printArray(int a[]);
- main()
- {
- int a[n];
- getArray(a);
- bubbleSort(a);
- printArray(a);
- }
- void getArray(int a[])
- {
- int i;
- for(i=0;i<n;i++)
- {
- printf("a[%d]=", i);
- a[i]=GetInteger();
- }
- }
- void bubbleSort(int a[])
- {
- int i, temp;
- for(i=0;i<n;i++)
- {
- if(a[i]>a[i+1])
- {
- temp=a[i];
- a[i]=a[i+1];
- a[i+1]=temp;
- }
- }
- if(isordered(a)) return;
- else bubbleSort(a);
- }
- bool isordered(int a[])
- {
- bool flag, i;
- flag=TRUE;
- for(i=0;i<n;i++)
- {
- if(a[i]>a[i+1])
- flag=FALSE;
- }
- if(flag==FALSE) return FALSE;
- if(flag==TRUE) return TRUE;
- }
- void printArray(int a[])
- {
- int i;
- for(i=0;i<n;i++)
- {
- printf("a[%d]=%d", i, a[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement