没有合适的资源?快使用搜索试试~ 我知道了~
代码如下:/*** 实现最大堆**/ #include <iostream>#include <cstring>#include <string>#include <algorithm>#include <cstdio> using namespace std;const int M = 10003; //定义数据节点class dNode{public: string name; int age; double score; dNode():name(“no name”), age(0), score(0.0){} dNode(string name, int age, double sco
资源详情
资源评论
资源推荐
堆基本操作实现最大堆堆基本操作实现最大堆
代码如下:
/**
* 实现最大堆
*
*/
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
const int M = 10003;
//定义数据节点
class dNode{
public:
string name;
int age;
double score;
dNode():name(“no name”), age(0), score(0.0){}
dNode(string name, int age, double score):name(name), age(age), score(score){}
bool operator < (const dNode & d){
return score < d.score;
}
bool operator > (const dNode &d){
return score > d.score;
}
bool operator = (const dNode &d){
name = d.name;age=d.age;score=d.score;
}
bool operator == (const dNode &d){
return name == d.name && age == d.age && score == d.score;
}
void swap(dNode & a, dNode & b){
dNode tmp = a;
a = b;
b = tmp;
}
void show(){
cout << “***************” << endl;
cout << “name: ” << name << endl;
cout << “age: ” << age << endl;
cout << “score: ” << score << endl;
}
};
//定义堆
template<class T>
class Heap{
public:
dNode h[M];
void heapify(int cur);
int n;
//数组下标从0开始
int L(int i){return (i << 1) + 1;}
int R(int i){return (i << 1) + 2;}
int P(int i){return (i – 1) >> 1;}
public:
Heap():n(0){}
weixin_38672731
- 粉丝: 5
- 资源: 952
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0