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
|
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
void swap(string * , string * );
int main()
{
string names[5]={"Marsh, alan", "turtle, tami", "booby, google",
"turner, ted", "rodgers, mimi"};
int ages [5]={10,20,30,40,50};
string * strPtr[5];
// load up pointers addresses
for (int i = 0; i <5; i++)
{
strPtr[i] = &names[i];
}
int smallest =1;
if(names[1] > names[2])
{
cout << "swap pointers " << endl;
swap( &strPtr[ 1 ], &strPtr[ smallest ] );
}
return 0;
}
void swap( string * element1Ptr, string * element2Ptr )
{
string * hold = *element1Ptr;
*element1Ptr = *element2Ptr;
*element2Ptr = hold;
}
|