Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
unfortunately im sitting at this problem for 4hours now, and it drives me crazy:

i got an 2 vectors as a members of my class.
the firstvector contains structs < with cstring Name, enum Kind and float transformation-factor>
and the vector with the sorting informations is filled by Enums for "Name"(0), "Kind"(1) and "transformation-factor"(2).
The Position of the Enum in the Vector tells us the Sort Order.
My Goal is to display the first vector data in a data grid, sorted by the users order.

Now i have problems to write a working functor, which shall tell the std::sort how to sort.

What I have tried:

The sorting functions should get the parameters and should stop the sortion as soon theres is a first matching pair, what is NOT l. == r.,
right now i not even can get the struct for the functor down in the .header,
also i have problems with the call of the functions in the .cpp, cause every step depends on the sorting-vector.
Who can help me and give me an example?
Posted
Updated 21-Jun-16 4:37am
Comments
[no name] 20-Jun-16 11:30am    
How is about to let your original data like it is and introduce a third vector managing "only" the sort indices?
Sergey Alexandrovich Kryukov 20-Jun-16 11:43am    
Not clear. What you want to achieve cannot be called "sorting", it it should stop before the end of sorting. No matter what it is, you should strictly formulate it. "l. == r." is not clear; you never introduced l or r, and this is not C++ code.
Probably you need to provide the code where you define vectors and the element types and clearly formulate the problem.
See also:
What have you tried so far?
—SA
Patrice T 20-Jun-16 12:21pm    
Show a sample of your data hexibiting the situation.

To achieve your own sort order you must overwrite the sorting algorithm, by overwriting the comparison operator "<" which is repeatly called in a sort call.

For a deeper inside read and understand the great article STL Sort Comparison Function.

Tip: make a small sample list and debug it to understand what is happening.
 
Share this answer
 
Comments
Dennis1990 5-Aug-16 8:49am    
thank you KarstenK! your great article made it in my Literature List of my Thesis.
helped me a lot :)
thank you for your help.
i used the STL Sort Comparision Funciton and could use the
Member < Operator
like it was described in the Article

thank you for your help,
next time ill use a functor :)
 
Share this answer
 
v2
Comments
[no name] 24-Jun-16 11:35am    
I don't see a reason why to vote a 1 for the Feedback. Except that the Feedback is not really descriptiv. But for this it would much more effective to write a comment. I let a 5 here for a more or less "new" member.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900