•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 426,575 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,645 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 5149 | Replies: 2 | Solved
•
•
Join Date: Dec 2006
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Hello there, okie, my problem today is i i have all this names,
and i have to sort them using insertion sort, i can sort number using insertion sort with no probs, but when it comes to strings, and stuff, i get lots of problems. so plz guyz help me out.
here is the code i tried,
i used the same procedure as sorting numbers, i don't know if that's the rite procedure.
John, Dave, Steve, Kevin,Andrew,Scott,Colin,Timothy,Zenon
and i have to sort them using insertion sort, i can sort number using insertion sort with no probs, but when it comes to strings, and stuff, i get lots of problems. so plz guyz help me out.
here is the code i tried,
i used the same procedure as sorting numbers, i don't know if that's the rite procedure.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string arnList[9]={"John", "Dave", "Steve", "Kevin","Andrew","Scott","Colin","Timothy","Zenon"};
int nLength=9;
int nTemp;
for (int iCv = 1; iCv < nLength; ++iCv)
{
//the new value to be inserted into a temporary location
nTemp = arnList[iCv];
// k is the index of the number to the left of the iCv.
for (int k = iCv-1; k >= 0 && arnList[k] > nTemp; k--)
{
arnList[k+1] = arnList[k];
}
arnList[k+1] = nTemp;
}
for(iCv=0;iCv<nLength;iCv++) cout<<arnList[iCv]<<" ";
cout<<endl;
return 0;
}•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Array Sorting on a User Supplied Element (Java)
- Alphabetical Order (Python)
- Help with changing GoDaddy's default sort order??? (PHP)
- Download manager script needed (Existing Scripts)
- binary search trees (Java)
- sort information in a listbox by name (C#)
Other Threads in the C++ Forum
- Previous Thread: Homework assistance
- Next Thread: I am having some issues with some basic .net c++



Threaded Mode