Answer to Question #44586 in C++ for Bull

Question #44586
write a function sort() to perform the sorting algorithm. I have almost finish the coding but i don't know how to sort the names by alphabetical order. Thanks.

#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
const int arraySize=20;
string name[arraySize]={"John","Catherine","Shelly","Zane","Ben","Tom","Albert","Melly","Danny","Jane","Elsa","Fiona","George"
<<"Harry","Idina","Kelly","Lance","Nandos","Patrick","Rose"};
int i,hold;

for(i=0;i<arraySize;i++)
{
cout<<" "<<a[i];
}

for(int pass=0;pass<arraySize-1;pass++)
{
for(i=0;i<arraySize-1;i++)
{
if(a[i]>a[i+1])
{
hold=a[i];
a[i]=a[i+1];
a[i+1]=hold;
}
}
}

for(i=0;i<arraySize;i++)
{
cout<<" "<<a[i];
}

return 0;
}
0
Expert's answer

Answer in progress...

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS