How:
----
Algorithm: Bubble Sort
Data Structures: None.
*/
#include < stdio.h >
/* constants */
#define N 10 /* size of array to sort */
#define FALSE 0
#define TRUE 1
/* function prototypes */
void bubble_sort (int A [ ], int n);
void read_array (int A [ ], int n);
void write_array (int A [ ], int n);
void efficient_bubble_sort(int A [ ], int n);
int main ( ){
/* read_array: reads input integers into a given array
Parameters: A - the array (output).
n - number of numbers to read (input).
Returns: no return value
Algorithm: Trivial.
*/
void read_array (int A [ ], int n){
/* write_array: writes the contents of an array of integers
Parameters: A - the array (input).
n - number of integers to write (input).
Returns: no return value
Algorithm: Trivial.
*/
void write_array (int A [ ], int n){
/* Bubble sort: Sorts a given array of numbers in an increasing order.
Parameters: A - array to sort (input + output parameter)
n - size of the array (input parameter)
Returns: no return value.
Algorithm: Bubble Sort.
*/
void bubble_sort(int A[ ], int n){
for (i = 0; i < n-1; i++){
/* Bubble sort: Sorts a given array of numbers in an increasing order.
Pameters: A - array to sort (input + output parameter)
n - size of the array (input parameter)
Returns: no return value.
Algorithm: Bubble Sort - stop when there was no change
in the previous iteration.
*/
void efficient_bubble_sort(int A[], int n){
while (( i < n - 1) && change){
change = FALSE;
for (j = n - 1 ; j > i; j --) { /* now A[0..i-1] is already
sorted */