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

Recommended Answers

All 2 Replies

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.

Here is a better insertion sort algorithm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.