fork download
  1. #include <queue>
  2. #include <vector>
  3. #include <iostream>
  4.  
  5. struct Cell
  6. {
  7. int m_totalCost;
  8. Cell(int totalCost=0) : m_totalCost(totalCost) {}
  9.  
  10. struct PriorityCompare
  11. {
  12. bool operator()(Cell const* lhs, const Cell* rhs) const
  13. {
  14. return rhs->m_totalCost < lhs->m_totalCost;
  15. }
  16. };
  17. };
  18.  
  19. std::priority_queue<Cell*, std::vector<Cell*>, Cell::PriorityCompare> g_path;
  20.  
  21. int main()
  22. {
  23. Cell first(rand() % 1000);
  24. Cell second(rand() % 1000);
  25. Cell third(rand() % 1000);
  26. Cell fourth(rand() % 1000);
  27. Cell fifth(rand() % 1000);
  28.  
  29. g_path.push(&first);
  30. g_path.push(&second);
  31. g_path.push(&third);
  32. g_path.push(&fourth);
  33. g_path.push(&fifth);
  34.  
  35. while (g_path.empty() == false) {
  36. Cell* cell = g_path.top();
  37. g_path.pop();
  38. std::cout << cell->m_totalCost << "\n";
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
383
777
793
886
915