Look I am new to C++. I am trying to perform a selection sort to read in 25 names and print as unsorted list with heading, prompt the user for ascending or descending. Then I want to sort print list in ascending or descending and sort heading. Here is what I have.
#include <iostream.h>
#include#include <iostream.h>
#include <string>
#include <list>
typedef std::list <std::string> StringList;
int main ()
{
int d=0, nCount = 25;
bool bIns = false;
char nsize[140];
StringList NameList;
StringList ::iterator it;
do
{
cout<<"Please enter the name of the person."<< (d+1)<< ":";
cin.getline (nsize, sizeof (nsize));
bIns = false;
for (it = NameList.begin ();it != NameList.end (); it++)
{
if (nsize< (*it)) //Uses the If and Else Statements
{
NameList.insert (it,nsize);
bIns = true;
break;
}
}
if (!bIns)//If the name was not inserted
d++;
}while (d< nCount);
d=0;
cout <<"\n\n\nNames\n----"<<endl;//Print sorted list
for (it = NameList.begin (); it !=NameList.end (); it++, d++)
cout <<""<<(d+1)<<":"<<(*it).c++ str() <<endl;
cout<<"Please enter names in ascending order";
cout<<"Please enter names in descending order";
return 0;
}
Is this right?
#include <iostream.h>
#include#include <iostream.h>
#include <string>
#include <list>
typedef std::list <std::string> StringList;
int main ()
{
int d=0, nCount = 25;
bool bIns = false;
char nsize[140];
StringList NameList;
StringList ::iterator it;
do
{
cout<<"Please enter the name of the person."<< (d+1)<< ":";
cin.getline (nsize, sizeof (nsize));
bIns = false;
for (it = NameList.begin ();it != NameList.end (); it++)
{
if (nsize< (*it)) //Uses the If and Else Statements
{
NameList.insert (it,nsize);
bIns = true;
break;
}
}
if (!bIns)//If the name was not inserted
d++;
}while (d< nCount);
d=0;
cout <<"\n\n\nNames\n----"<<endl;//Print sorted list
for (it = NameList.begin (); it !=NameList.end (); it++, d++)
cout <<""<<(d+1)<<":"<<(*it).c++ str() <<endl;
cout<<"Please enter names in ascending order";
cout<<"Please enter names in descending order";
return 0;
}
Is this right?