Custom sort in C++ adding attributes
If you are learning the ways of sort, then yes it would be complicated. Just add every condition in the swap instead of just
Bubble sort is not as quick as quick sort.
You should try that and yes, as software synthesis said, there is simply no need to re-invent the wheel. There is a sort function in algorithm. All you need to do is define in a comparator function.
To know how to use a comparator function, you can read this.
It is very easy. Just like any other ordinary function. Its return type is blue and takes 2 parameters a and b.
Suppose a and b are 2 consecutive elements of the vector.
If a and b is in proper placements i.e a<b (for ascending) then return true, else return false.
But I have 3 properties to be considered;
Do I need 3 comparator functions? or 1 to do all of them ? Then how many parameter would there be? 6?
You don't need to pass all the properties. Just pass the two objects and access their properties, from within the function. Here is a simple comparator function to help you out
bool comparator(items a,items b)
else if (a.weight<b.weight)
Try this and I think you shall get it soon.
Thanks a lot Software Synthesis. I got that finally. It's really amazing.