Next problem :-)
I have created a class to do several things. It defines a structure that contains 4 columns. I have a list of these structures contained in an array. What i am wanting to do is allow the user to define with column they would like to sort by but I cant quite figure out what I need to do. I figured I could write a functions for each column, but am unclear on how to implement it. I can provide my entire code, or snippets if necessary; else just point me in the right direction please!
Why not use a std::vector instead of an array?
You can just make four functions. Each for every column. Then the value you use to sort will be that column, but when you swap, you can swap the structure itself. For example, you have two structures lets say in a sorting function:
You can combine then the 4 functions into one and add the column as a parameters.
void sortCol1(myStruct structs)
if (myStruct->column1 > myStruct->column1)
myStruct* temp = myStruct;
myStruct = myStruct;
myStruct = temp;
Well, Im using arrays because the assignment requires. :-(
That explanation does help though. Only thing im confused about is how to call the columns.
My Declaration of class and structure looks like this
> string c1,c2,c3,c4;
would make it a lot easier to say (using a number) which column you want.