the program i have to make is as follows:
use the string comparison function and the sorting array techniques to write a program that alphabetizes a list of strings. use 10 town names for your program.
and this si what i have made.... and it doesnt work:
#include<iostream>
using namespace std;
#include<iostream>
using namespace std;
#include<cstring>
using std::strncmp;
int main()
{
const int ArraySize = 10;
const char *Array[] = { "Toronto", "Montreal", "Alberta", "Quebec", "NewYork", "Calgary", "Edmonton", "NewJersey", "Ontario", "California" };
cout << "The unsorted arangement of the town names is: \n"<<endl;
for ( int i = 0; i < ArraySize; i++ )
{
cout <<" " << Array[i];
cout << endl << "\n";
}
cout << "The sorted arangement of the town names is: \n"<<endl;
for ( int next = 0; next < ArraySize; next++ )
{
if ( strncmp(Array[next],Array[next-1],3) == -1)
{
Array[next] = Array[next];
}
if( strncmp(Array[next],Array[next-1],3) == 1)
{
Array[next] = Array[next - 1];
}
}
for ( int j = 0; j < ArraySize; j++ )
{
cout <<" " << Array[j];
cout << endl << "\n";
}
return 0;
}
any ideas on what is wrong? and what solution is there??
thank you