I'm working on a program that will get a list of words from the user and rearrange it in alphabetical order. So far it works but I think it may have some memory issues because I was testing an alternative way of asking the user how many arrays will be needed other than dynamic memory.
Here is the code:
#include<string>
using namespace std;
int main()
{
int n; //Used to set the number of arrays of MiString and MiNewString.
cout << "How many words do you want the list to contain? ";
cin >> n;
string MiString[n], MiNewString[n], Temp; //This does work but there may be issues I'm unaware of.
int i, ii, _Place;
for (i=0; i<n; i++) //Get the list from the user.
{
cout << "Input a word: ";
cin >> MiString[i];
}
for (i=0; i<n; i++) //Alphabetize list
{
for (ii=0, _Place=0; ii<n; ii++)
{
if (MiString[i] > MiString[ii]) {_Place ++;}
}
MiNewString[_Place] = MiString[i];
}
cout << "\nYour alphabetized list is:\n";
for (i=0; i<n; i++) \\Print new list
{
cout << MiNewString[i] << "\n";
}
return 0;
}
If you see any problems with this please tell me.