⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 heap.cpp

📁 此程序实现了堆排序,并且使用了MFC的图形界面,非常实用
💻 CPP
字号:
// Heap.cpp: implementation of the CHeap class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "HeapSort.h"
#include "Heap.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

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

CHeap::CHeap()
{

}

CHeap::~CHeap()
{

}

HeapNode * CHeap::CreateHeap(int a[], int n,int k)
{
	HeapNode *p;
    if ((n>7)||(n>7-k)) return NULL;
	p = new(HeapNode);
	p->data = a[n-1];
	p->lchild = CreateHeap(a,2*n,k);
	p->rchild = CreateHeap(a,2*n+1,k);
	return p;
}




void CHeap::DrawHeap(CClientDC *pDC,HeapNode *node,int deep,int x, int y)
{
	if ( node->lchild != NULL )
	{
		pDC->MoveTo( x, y );	pDC->LineTo( x-50+deep*5, y+50 );
		DrawHeap( pDC, node->lchild, deep+1, x-50+deep*5, y+50 );
	}
	if ( node->rchild != NULL )
	{
		pDC->MoveTo( x, y );	pDC->LineTo( x+50-deep*5, y+50 );
		DrawHeap( pDC, node->rchild, deep+1, x+50-deep*5, y+50 );
	}
	CString str;
	str.Format("%d",node->data);
	pDC->TextOut( x-3, y-7, str );

}

⌨️ 快捷键说明

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