   sorting  a deque struct?
  i have a  struct struct SCords{ int x; int y; int value;}deque <SCords*> myCords;now once i have push_back  a few item into  myCords , i want to be able to  sort them by value.sort(myCords.begin(),myCords.end(),swapValue);bool swapValue (SCordsMap* first, SCordsMap* second){if (first->value < second->value)return false;elsereturn true;}it compiles but  gives a runtime error how would i  write the sort, and then swapvalue please   
  What kind of runtime error do you get?With your sort predicate, you can just write return first->value >= second->value;Maybe off-topic, but what's the reason you're using a deque over a vector?   ;  Also, why are you using a container of pointers instead of a container of objects?   ;  Actually your sort function isn't valid. One of the requirements for a sort predicate is that for all x !comp(x, x). Or to put it another way it has to be < or > but can't be <= or >=.   ;Quote:Original post by SiCraneActually your sort function isn't valid. One of the requirements for a sort predicate is that for all x !comp(x, x). Or to put it another way it has to be < or > but can't be <= or >=.But the OP wasbool swapValue (SCordsMap* first, SCordsMap* second){    if (first->value < second->value)   return false;    else   return true;}i.e. the same as bool swapValue (SCordsMap* first, SCordsMap* second){    return first->value > second->value;}.   ;  Wait. If the value of both pointers is 5. Then 5 < 5 is false. So the OP's function returns true.   ;Quote:Original post by phresnelQuote:Original post by SiCraneActually your sort function isn't valid. One of the requirements for a sort predicate is that for all x !comp(x, x). Or to put it another way it has to be < or > but can't be <= or >=.But the OP was*** Source Snippet Removed ***i.e. the same as *** Source Snippet Removed ***.Actually, those two methods are not equivalent.The big difference is that if (first->value < second->value) return false; else return true; returns true if both values are equal, while return first->value > second->value; returns false.> is not the inverse of <.   ;Quote:Original post by Anthony SerranoQuote:Original post by phresnelQuote:Original post by SiCraneActually your sort function isn't valid. One of the requirements for a sort predicate is that for all x !comp(x, x). Or to put it another way it has to be < or > but can't be <= or >=.But the OP was*** Source Snippet Removed ***i.e. the same as *** Source Snippet Removed ***.Actually, those two methods are not equivalent.The big difference is that if (first->value < second->value) return false; else return true; returns true if both values are equal, while return first->value > second->value; returns false.> is not the inverse of <.Upon having a coffee pause I came to re-think my solution. Let me solve it again:Original:    if (first->value < second->value)   return false;    else   return true;If we want to make it a one-liner, it becomes    return !(first->value < second->value)of course [<] = ![>=] (operator calculus, yay), so    return first->value >= second->value.so you are completely right and I apologize for my failure.   