Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selection Sort Very Important

Status
Not open for further replies.

ddeemac

Programmer
Dec 28, 2000
12
0
0
US
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<<&quot;Please enter the name of the person.&quot;<< (d+1)<< &quot;:&quot;;
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 <<&quot;\n\n\nNames\n----&quot;<<endl;//Print sorted list
for (it = NameList.begin (); it !=NameList.end (); it++, d++)
cout <<&quot;&quot;<<(d+1)<<&quot;:&quot;<<(*it).c++ str() <<endl;

cout<<&quot;Please enter names in ascending order&quot;;
cout<<&quot;Please enter names in descending order&quot;;

return 0;
}

Is this right?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top