1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| #include<iostream> #include<cstdio> #include<queue>
using namespace std;
struct cmp { bool operator()(int x,int y) { return x>y; } };
typedef struct nod { int x,y; friend bool operator < (nod a,nod b) { return a.y>b.y; } } node;
int main() { priority_queue<int>simple; priority_queue<int,vector<int>,cmp>define; priority_queue<node>heap; int a[10]={20,50,3202,20,503,12,56,62,50,80}; printf("Simple Test:\n"); for (int i=0;i<10;i++) simple.push(a[i]); for (int i=1;i<=10;i++) { int temp=simple.top(); simple.pop(); printf("%d\n",temp); } printf("Define Test:\n"); for (int i=0;i<10;i++) define.push(a[i]); for (int i=1;i<=10;i++) { int temp=define.top(); define.pop(); printf("%d\n",temp); } printf("Heap Test:\n"); node b[10]={{1,2},{2,100},{3,4},{4,50},{5,6},{6,7},{7,8},{8,9},{9,10},{10,11}}; for (int i=0;i<10;i++) heap.push(b[i]); for (int i=1;i<=10;i++) { node temp=heap.top(); heap.pop(); printf("%d %d\n",temp.x,temp.y); } printf("%d",2<1); return 0; }
|