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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include <iostream>
#include <cstring>
using namespace std;
void pause ();
void BubbleSort( const char *array[][] , int size );
int arraySize = 100;
int main ()
{
// Declaration section
int i = 0;
const int arraySize = 15;
const char *songs[15][80] = { {"Honolulu"}, {"Aiea"}, {"Pearl City"}, {"Wahiawa"},{"Kalihi"}, {"Waipahu"}, {"Pearl Harbor"}, {"Hawaii Kai"},
{"Mililani"}, {"Waikiki"}, {"Kaneohe"}, {"Kapolei"}, {"Salt Lake"}, {"Ewa Beach"}, {"Manoa"} };
//Original print out of listing of cities
cout << "The original listing of cities:\n\n";
for ( i = 0; i < arraySize; ++i )
cout << songs[ i ][0] << "\n" ;
pause();
// Sort the array
BubbleSort( &songs[15][0] , arraySize );
//Print out of listing of cities in alphabetical order
cout << "The alphabetical listing of cities:\n\n";
for ( i = 0; i < arraySize; ++i )
cout << songs[ i ][0] << "\n" ;
pause ();
return 0;
}
void BubbleSort( const char *array[15][0] , int size )
{
int result;
for ( int pass = 0; pass < size - 1 ; ++pass ){
for ( int j = 0; j < size - 1 - pass; ++j ){
result = strcmp (array[j][0], array[j+1][0]);
if (result > 0)
swap ( array[j][0] , array[j+1][0] );
}
}
}
/*
void bubbleSort( char songs[100][80], int arraySize)
{
int i,j;
char temp[80];
for (i=0; 1<(arraySize -1); i++)
{
for (j=i+1; j < arraySize; j++)
{
if (strcmp(songs[i],songs[j]) <0)
{
strcpy(temp, songs[j]);
strcpy(songs[j], songs[i]);
strcpy(songs[i], temp);
}
}
}
} */
void pause ()
{
cout << "\nPress any key to continue...";
getchar();
cout << "\r";
cout << " ";
cout << "\r";
}
|