Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <tchar.h>
  3. #include <queue>
  4.  
  5. //////////////////////////////////////////////////////////////////////////
  6.  
  7. class Node
  8. {
  9. public:
  10.   Node()  {};
  11.   virtual ~Node() {};
  12. };
  13.  
  14. //////////////////////////////////////////////////////////////////////////
  15.  
  16. class Sorter
  17. {
  18. public:
  19.   Sorter()  {};
  20.  
  21.   inline bool operator()(Node * a, Node * b) const
  22.   {
  23.     return rand() % 1;
  24.   }
  25. };
  26.  
  27. //////////////////////////////////////////////////////////////////////////
  28.  
  29. typedef std::priority_queue<Node *, std::vector<Node*>, Sorter> MyPriorityQueue;
  30.  
  31. //////////////////////////////////////////////////////////////////////////
  32.  
  33. class Traverser
  34. {
  35. public:
  36.   Traverser()  {};
  37.   virtual ~Traverser()  {};
  38.  
  39.   void test()
  40.   {
  41.     Node * pNode = new Node();
  42.     mDistanceQueue = &MyPriorityQueue(Sorter());
  43.     mDistanceQueue->push(pNode);    // падаем тут. MSVS 2005 c включенной /Ox
  44.  
  45.     Node * node = mDistanceQueue->top();    // или тут, зависит от погоды
  46.    
  47.     delete pNode;
  48.   }
  49.  
  50. private:
  51.   MyPriorityQueue *  mDistanceQueue;
  52. };
  53.  
  54. //////////////////////////////////////////////////////////////////////////
  55.  
  56. int _tmain(int argc, _TCHAR* argv[])
  57. {
  58.   Traverser * pNew = new Traverser();
  59.   pNew->test();
  60.  
  61.   return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement