Advertisement
SparrowG

Where does the compare function go?

Dec 16th, 2011
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include<vector>
  2. #include<algorithm>
  3.  
  4. struct Square{
  5.     int color; //value 1 to 10
  6. };
  7. struct State{
  8.     vector<Square> list;
  9.     int color_weight[] = {4,3,5,2,4,1,6,4,5,9}; //These values keep changing.
  10.     operator<(Square& a, Square& b);
  11.     void sortTheList();
  12.    
  13. };    
  14.  
  15. bool State::operator<(Square& a, Square& b){
  16.     if (color_weight[a.color]< color_weight[b.color]){
  17.         return true;
  18.     }
  19.     return false;
  20. }
  21.  
  22. void Square::sortTheList(){
  23.     sort(list.begin(),list.end());
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement