minleftlisttree.cpp

来自「插入和删除最小元素操作」· C++ 代码 · 共 71 行

CPP
71
字号
// MinLeftistTree.cpp: implementation of the MinLeftistTree class.
//
//////////////////////////////////////////////////////////////////////

#include "MinLeftlistTree.h"

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

LeftlistNode* MinLeftlistTree::MinUnion(LeftlistNode *a, LeftlistNode *b )
{
	if( a->data.key > b->data.key )
	{
		LeftlistNode *t = a;
		a = b;
		b = t;
	}
	if( !a->RightChild)
		a->RightChild = b;
	else
		a->RightChild = MinUnion( a->RightChild, b );

	if(!a->LeftChild)
	{
		a->LeftChild = a->RightChild;
		a->RightChild = 0;
	}
	else if( a->LeftChild->shortest < a->RightChild->shortest )
	{
		LeftlistNode *t = a->LeftChild;
		a->LeftChild = a->RightChild;
		a->RightChild = t;
	}

	if( !a->RightChild )
		a->shortest = 1;
	else
		a->shortest = a->RightChild->shortest + 1;
	return a;
}

void MinLeftlistTree::Insert( const element& x  )
{
}

void MinLeftlistTree::MinCombine(MinLeftlistTree* b)
{
	if(!root) 
		root = b->root;
	else if(b->root) 
		root = MinUnion(root,b->root);
	b->root = 0;
}

element* MinLeftlistTree::Delete( element& del )
{
	LeftlistNode* empty = 0;
	if( root == empty )
	{
		return 0;
	}

	return &del;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?