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
|
# include <iostream>
using namespace std;
void sort(string *sA,size_t strSize)
{
for(size_t i = 0; i < strSize-1; i++)
{
for(size_t j = i; j < strSize; j++)
{
if(sA[i] > sA[j])
{
sA[i].swap(sA[j]);
}
}
}
}
int main()
{
string str[] = {"I","wrote","a","small","program","i","which","I","use","a","bubble","sort",
"function","to","sort","","strings","in","an","array","in","ascending","order"};
size_t strSize = sizeof(str)/sizeof(*str);
sort(str,strSize);
for(size_t i=0;i<strSize;i++)
cout << str[i] << endl;
return 0;
}
|