PDA

View Full Version : std::sort


Extrawurst
10-07-2003, 12:49 PM
Hello, can please someone explain the way to use the std::sort-algorithm!
Well, I have a self-defined struct: MyStruct and a vector<MyStruct>, and now i want to sort this vector with the std::sort-template-function! But i never used template-functions before with their weird declaration!
So please help me!

Ps: it's important that i can implement my own compare-function, i think this is possible with std::sort isn't it ?!

Dia Kharrat
10-07-2003, 02:31 PM
check this page, it should answer your question:

http://www.codeproject.com/vcpp/stl/stdsort.asp

If you have bugs or compilation errors, you can post some code if you want, so that one can help you better.

anubis
10-07-2003, 05:07 PM
:) i was about to write up a lengthy text... but that explains it pretty well

Extrawurst
10-07-2003, 10:01 PM
Okay, thanks it seems to be quite easy, but one last question! is it right that the third parameter of std::sort has to be the overloaded "()"-operator getting two pointers of its class and compare them ?

Extrawurst
10-08-2003, 06:54 AM
okay i got it now, i didn't read the explanations carefully the first time ;)