设为首页 加入收藏

TOP

二叉堆对结构体使用优先队列
2013-11-20 14:24:09 来源: 作者: 【 】 浏览:137
Tags:结构 使用 优先 队列
    ZOJ 2724 Windows Message Queue(对结构体使用优先队列)
    /*
    * ZOJ_2724.cpp
    *
    *  Created on: 2013年11月7日
    *      Author: Administrator
    */
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <queue>
    using namespace std;
    struct MES {
    char str ;
    int mes;
    int p;
    int id;
    bool operator<( const MES& b)const {//特别要注意这种写法…
    if (p != b.p) {
    return p > b.p;
    }
    return id > b.id;
    }
    };
    int main() {
    char s[26];
    priority_queue<MES> q;//对结构体使用优先队列
    MES tmp;
    while (scanf("%s", s) != EOF) {
    int index = 0;
    if (strcmp(s, "PUT") == 0) {
    scanf("%s %d %d", tmp.str, &tmp.mes, &tmp.p);
    tmp.id = index++;
    q.push(tmp);
    } else {
    if (q.empty()) {
    printf("EMPTY QUEUE!\n");
    } else {
    tmp = q.top();
    q.pop();
    printf("%s %d\n", tmp.str, tmp.mes);
    }
    }
    }
    return 0;
    }

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇前序遍历二叉树递归解法 下一篇伞兵降落的精准编程实例

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Java 学习线路图是怎 (2025-12-25 15:19:15)
·关于 Java 学习,有 (2025-12-25 15:19:12)
·有没有Java swing教 (2025-12-25 15:19:09)
·Start, Stop, and Di (2025-12-25 14:50:57)
·C语言入门教程:零基 (2025-12-25 14:50:54)