60 314
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #44587 in C++ for Bull

Question #44587
write a function sort() to perform the sorting algorithm. 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;
}
Expert's answer

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions