#include <iostream>
#include <string>
void SortArray( std::string* array[],int iElems );
void OutArray( std::string* array[],int iElems );
int main()
{
std::string first ="abolone";
std::string second="bobby";
std::string third ="caral";
std::string fourth="danny";
std::string *sArray[4];
sArray[0]=&second;
sArray[1]=&fourth;
sArray[2]=&first;
sArray[3]=&third;
std::cout << "Before sort:" <<
std::endl;
OutArray( sArray,4 );
std::cout << "After sort:" <<
std::endl;
SortArray( sArray,4 );
OutArray( sArray,4 );
return 0;
}
void SortArray( std::string* array[],int iElems )
{
std::string sTemp,sHold;
int iPass=1;
bool bExchanges=true;
while ( iPass < iElems && bExchanges )
{
bExchanges=false;
for ( int i=0;i<iElems-1;i++ )
{
sTemp=*array;
sHold=*array[i+1];
if( sTemp.compare( sHold )==1 )
{
sTemp =*array;
*array =*array[i+1];
*array[i+1]=sTemp;
bExchanges =true;
}
}
}
}
void OutArray( std::string* array[],int iElems )
{
for( int i=0;i<iElems;i++ )
{
std::cout << "array[" << i << "]=" << *array <<
std::endl;
}
}
Mike L.G.
mlg400@blazemail.com