|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (10 bit)
|
2d string array sorting....
i cant find any good algoritms to sort and array of strings in alphabetical order. anyone know of a good one that is used for this purpose or at least close, so i can modify it?
thanks Last edited by GSXdan; 09-11-2003 at 05:50 PM. |
|
|
|
|
|
#2 |
|
Registered User
Join Date: Nov 2001
Posts: 1,965
|
sorting strings is similar to sorting numbers, the only difference is comparing two strings, while you can use the < or > operators with numbers, you can't do so with C strings, some of the options you have:
using Another option is using the string class that comes with C++ STL (Standard Template Library), again check out cppreference for more info. As for the sorting algorithm itself, there a lot of algorithms, if you want something simple, use bubble sort, it works fine for small arrays (like 20) if you have larger arrays, you may consider using heap sort or quick sort, I recommend heap sort because it's easier to understand and implement for a new comer to sorting. Just Google for the sort algorithm name and you'll find info about it, read it, and if you can't understand anything, just post ![]() EDIT: strcmp: http://cppreference.com/stdstring_details.html#strcmp c++ string: http://cppreference.com/cppstring.html Bubble sort: http://linux.wku.edu/~lamonml/algor/sort/bubble.html Heap sort: There used to be a great site for heap sort, but I can't manage to find it right now
Last edited by aym; 09-14-2003 at 07:33 AM. |
|
|
|
|
|
#3 |
|
Member (10 bit)
|
yea i found a modified bubble sort that i came up w/ last year that words just fine for this:
Code:
void Sort(char words[][20], int numwords) {
int last, next, test;
char temp[20];
for(int i=1;i
|
|
|
|
|
|
#4 |
|
Member (10 bit)
|
the code isnt showing up correctly for some reason??? if you want to see it i can post the cpp file.
^dan |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|