日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C++實(shí)現(xiàn)堆
#include 
using namespace std;
#include 
#include 

//仿函數(shù)
template
struct Less
{
	bool operator()(const T& left, const T& right)
	{
		return left < right;
	}
};

template
struct Greater
{
	bool operator()(const T& left, const T& right)
	{
		return left > right;
	}
};

template>//默認(rèn)為小堆
class Heap
{
public:
	Heap()
	{}

	Heap(const T* array, size_t size)
	{
		for (size_t i = 0; i < size; ++i)
		{
			_a.push_back(array[i]);
		}

		for (int i = (_a.size()-2)/2; i >= 0; --i)
		{
			_AdjustDown(i);
		}
	}

	void Push(const T& x)
	{
		_a.push_back(x);

		_AdjustUp(_a.size()-1);
	}

	void Pop()
	{
		assert(!_a.empty());

		swap(_a[0], _a[_a.size()-1]);
		_a.pop_back();
		_AdjustDown(0);
	}

	T& GetTop()
	{
		assert(!_a.empty());

		return _a[0];
	}

	bool Empty()
	{
		return _a.empty();
	}

	size_t Size()
	{
		return _a.size();
	}

	void Print()
	{
		for (size_t i = 0; i < _a.size(); ++i)
		{
			cout<<_a[i]<<" ";
		}
		
		cout< 0)
		{
			if (compare(_a[child], _a[parent]))
			{
				swap(_a[parent], _a[child]);

				child = parent;
				parent = (child-1)/2;
			}
			else
			{
				break;
			}
		}
	}

protected:
	vector _a;
};


void Test()
{
	int a[10] = {10, 11, 13, 12, 16, 18, 15, 17, 14, 19};
	Heap> hp1(a, sizeof(a)/sizeof(a[0]));
	hp1.Print();
	cout<<"size:"<

C++實(shí)現(xiàn)堆

10年積累的成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有加查免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。


分享題目:C++實(shí)現(xiàn)堆
當(dāng)前網(wǎng)址:http://www.dlmjj.cn/article/jgjcoc.html