1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <iostream>
#include <string>
using namespace std;
//Function Prototypes
void displayArray(string[], int);
void bubbleSort(string[], int);
int main ()
{
const int NUM_NAMES = 8;
string names [NUM_NAMES] = {"Collings, Bill ", "Smith, Bart ", "Allen, Jim ", "Griffin, Jim ", "Stamey, Marty ", "Rose, Geri", };
//Display the unsorted array.
displayArray(names, NUM_NAMES);
//Sort the array.
bubbleSort(names, NUM_NAMES);
return 0;
}
void displayArray(string j[], int SIZE)
{
for (int i=0; i < SIZE; i++)
cout << j[i] << endl;
}
void bubbleSort(string array[], int size)
{
cout << "Here are the sorted names:\n";
cout << "---------------------------\n";
int j;
int temp;
for (int i=0;i<(size-1);i++){
for(j=i+1;j<size;j++){
if (array[j] < array[i]){
temp = array[j];
array[j] = array[i];
array[i] = temp;
cout << array[i] << endl;
}
}
}
}
|