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;
}
1
Expert's answer
2014-07-31T09:23:30-0400
The answer to the question is available in the PDF file https://www.assignmentexpert.com/https://www.assignmentexpert.com/homework-answers/programming-answer-44587.pdf

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

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS