fork download
  1.  
  2. #include <iostream>
  3. #include <queue>
  4. using namespace std;
  5.  
  6. void showpq(
  7. priority_queue<int, vector<int>, greater<int> > g)
  8. {
  9. while (!g.empty()) {
  10. cout << ' ' << g.top();
  11. g.pop();
  12. }
  13. cout << '\n';
  14. }
  15.  
  16. void showArray(int* arr, int n)
  17. {
  18. for (int i = 0; i < n; i++) {
  19. cout << arr[i] << ' ';
  20. }
  21. cout << endl;
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27. int arr[6] = { 10, 2, 4, 8, 6, 4 };
  28. priority_queue<int, vector<int>, greater<int> > gquiz(
  29. arr, arr + 6);
  30.  
  31. cout << "Array: ";
  32. showArray(arr, 6);
  33.  
  34. cout << "Priority Queue : ";
  35. showpq(gquiz);
  36.  
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Array: 10 2 4 8 6 4 
Priority Queue :  2 4 4 6 8 10