Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 24th, 2012  |  syntax: None  |  size: 0.63 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <algorithm>
  2. #include <list>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. struct comparer {
  7.              int this_node;
  8.  
  9.             comparer(int node) : this_node(node) {} // wtf? är det här ok?
  10.  
  11.              bool operator()(int a, int b) {
  12.                  return (a+this_node > b);//(d(this_node,a) < d(this_node,b));
  13.              }
  14.          };
  15.  
  16. int main()
  17. {
  18.     int foo[] = {55, 22, 33, 11, -11, -33};
  19.     list<int> mylist (foo, foo+sizeof(foo)/sizeof(int));
  20.  
  21.     mylist.sort(comparer(32));
  22.  
  23.     for (list<int>::iterator it=mylist.begin(); it!=mylist.end(); ++it)
  24.         cout << " " << *it;
  25.     cout << endl;
  26. }