0

So Basically I have a 4 x 2 array of Chars* that I need sorted alphabetically by the first column only. The Array starting out looks like:

Choices[0][0] = "CCleaner";
    Choices[0][1] = "Utilities";
    
    Choices[1][0] = "SIW";
    Choices[1][1] = "Information";
    
    Choices[2][0] = "MalwareBytes";
    Choices[2][1] = "Virus";
    
    Choices[3][0] = "CCleanerx";
    Choices[3][1] = "Utilities";

And I need it to be:

Choices[0][0] = "CCleaner";
    Choices[0][1] = "Utilities";

    Choices[1][0] = "CCleanerx";
    Choices[1][1] = "Utilities";
    
    Choices[2][0] = "MalwareBytes";
    Choices[2][1] = "Virus";
    
    Choices[3][0] = "SIW";
    Choices[3][1] = "Information";

As you can see, alphabetically (ignoring the second columns value).

I'm having a hard time finding what i need to put in its csort call, right now I'm using:

int wxListCtrlComparedecend(const void* first, const void* second)
{
    const char **ia = (const char **)first;
    const char **ib = (const char **)second;   
   return strcmp(*ia, *ib);

}

That sorts all items linearly, and I have no clue how to only sort by 1st column.

Thanks in advanced,
-Nathan

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Ancient Dragon
0

You will most likely have to write your own sort algorithm and swapping, so that you can keep both colums together when a swap is needed.

If you have never written a sort algorithm, then I will suggest the Insertion Sort, because it's the easiest to implement, even though it might be the slowest to run.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.