Tassos

priority_queue πως συγκρίνει;

May 12th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1.     #include <iostream>  
  2.     #include <queue>  
  3.     using namespace std;  
  4.      
  5.     struct compare  
  6.     {  
  7.       bool operator()(const int& l, const int& r)  
  8.       {  
  9.           return l > r;  
  10.       }  
  11.     };  
  12.      
  13.     int main()  
  14.     {  
  15.         priority_queue < int , vector<int>, compare > pq;  /* Εδώ ΔΕΝ μπορώ να καταλάβω γιατί παίρνει 3 ορίσματα;
  16. Άντε οκ να έπαιρνε ένα vector από ακέραιους (2ο όρισμα).. και μετά στο άλλο όρισμα είναι η συνάρτηση με την οποία θα κάνει την σύγκριση ( 3ο όρισμα ), στην αρχή όμως γιατί παίρνει και ένα int (1ο όρισμα ) ;; Αυτό δε καταλαβαίνω... */
  17.      
  18.  
  19.         pq.push(3);  // και μετά πάει εδώ και το παίζει πολύ cool και δίνει μονάχα ένα όρισμα.. Αυτό που αποθηκεύετε ;
  20.         pq.push(5);  
  21.         pq.push(1);  
  22.         pq.push(8);  
  23.         while ( !pq.empty() )  
  24.         {  
  25.             cout << pq.top() << endl;  
  26.             pq.pop();  
  27.         }  
  28.         cin.get();  
  29.     }  
  30.  
  31.  
  32.  
  33. Από εδώ το βρήκα :
  34. http://www.technical-recipes.com/2011/priority-queues-and-min-priority-queues-in-c/
Advertisement
Add Comment
Please, Sign In to add comment