算法设计、分析与实现 从入门到精通 C、C++和Java 这本书的堆实现85页C++语言实现有问题

在第86页的代码中少了#include <functional>这个头文件,编译时报如下错误:#include <iostream>

1>f:\算法导论\二叉堆\二叉堆\main.cpp(12) : error C2065: 'less' : undeclared identifier
1>f:\算法导论\二叉堆\二叉堆\main.cpp(12) : error C2062: type 'int' unexpected
1>f:\算法导论\二叉堆\二叉堆\main.cpp(17) : error C2065: 'greater' : undeclared identifier
1>f:\算法导论\二叉堆\二叉堆\main.cpp(17) : error C2062: type 'int' unexpected

加上该头文件后编译通过。


#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
	int h[]={4,1,3,2,16,9,10,14,8,7,10,23,44,1,5,6,9,7,2,5,6,3,15,200,1,2,0,33,999};
	int Num=sizeof(h)/sizeof(h[0]);

	make_heap(h,h+Num,less<int>());
	cout<<"max heap:"<<endl;
	copy(h,h+Num,ostream_iterator<int>(cout," "));
	cout<<endl;

	make_heap(h,h+Num,greater<int>());
	cout<<"min heap:"<<endl;
	copy(h,h+Num,ostream_iterator<int>(cout," "));
	cout<<endl;

	return (EXIT_SUCCESS);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值