优先队列(结构体)

//最大最小堆

struct node

{

    int i,n;

    node (){}

    node (int x,int y){

      i=x;n=y;

    }

    bool operator<(const node& b) const

    {

        return n>b.n;

    }

};

int main()

{

 

   priority_queue<node> Q;

   Q.push(node(1,2));

   Q.push(node(2,3));

   Q.push(node(1,3));

   Q.push(node(3,4));

   while(!Q.empty())

   {

       printf("%d %d\n",Q.top().i,Q.top().n);

       Q.pop();

   }

 

   return 0;

}

posted @ 2012-11-24 12:14  ♂咱說 ろ算  阅读(323)  评论(0编辑  收藏  举报