//pizza01.cpp
//Authors: AOU
#include <iostream.h>
void sortBubble(int array[], int low, int high);
void display(int array[], int low, int high);
void main(void)
{
int a[]={21, 12, 30, 19, 21, 69, 13, -1};
int n = sizeof(a)/sizeof(a[0]);
cout << "n = " << n << endl;
display(a, 0, n-1);
sortBubble(a, 0, n-1);
display(a, 0, n-1);
}
void display(int array[], int low, int high)
{
for (int i=low; i<= high; i++)
cout << array[i] << ' ';
cout << endl;
}
void sortBubble(int array[], int low, int high)
{
bool sorted;
do
{
sorted = true;
for (int i=low; i<high; i++)
{
if (array[i] > array[i+1])
{
int temp = array[i];
array[i] = array[i+1];
array[i+1] = temp;
sorted = false;
}
}
}
while (!sorted);
}
|