資源簡介
MFC畫二叉樹,前序創建,前序 中序 后序 廣度遍歷。判斷滿二叉樹

代碼片段和文件信息
//?Binarytree.cpp?:?Defines?the?class?behaviors?for?the?application.
//
#include?“stdafx.h“
#include?“Binarytree.h“
#include?“BinarytreeDlg.h“
#ifdef?_DEBUG
#define?new?DEBUG_NEW
#undef?THIS_FILE
static?char?THIS_FILE[]?=?__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//?CBinarytreeApp
BEGIN_MESSAGE_MAP(CBinarytreeApp?CWinApp)
//{{AFX_MSG_MAP(CBinarytreeApp)
//?NOTE?-?the?ClassWizard?will?add?and?remove?mapping?macros?here.
//????DO?NOT?EDIT?what?you?see?in?these?blocks?of?generated?code!
//}}AFX_MSG
ON_COMMAND(ID_HELP?CWinApp::onhelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//?CBinarytreeApp?construction
CBinarytreeApp::CBinarytreeApp()
{
//?TODO:?add?construction?code?here
//?Place?all?significant?initialization?in?InitInstance
}
/////////////////////////////////////////////////////////////////////////////
//?The?one?and?only?CBinarytreeApp?object
CBinarytreeApp?theApp;
/////////////////////////////////////////////////////////////////////////////
//?CBinarytreeApp?initialization
BOOL?CBinarytreeApp::InitInstance()
{
AfxEnableControlContainer();
//?Standard?initialization
//?If?you?are?not?using?these?features?and?wish?to?reduce?the?size
//??of?your?final?executable?you?should?remove?from?the?following
//??the?specific?initialization?routines?you?do?not?need.
#ifdef?_AFXDLL
Enable3dControls(); //?Call?this?when?using?MFC?in?a?shared?DLL
#else
Enable3dControlsStatic(); //?Call?this?when?linking?to?MFC?statically
#endif
CBinarytreeDlg?dlg;
m_pMainWnd?=?&dlg;
int?nResponse?=?dlg.DoModal();
if?(nResponse?==?IDOK)
{
//?TODO:?Place?code?here?to?handle?when?the?dialog?is
//??dismissed?with?OK
}
else?if?(nResponse?==?IDCANCEL)
{
//?TODO:?Place?code?here?to?handle?when?the?dialog?is
//??dismissed?with?Cancel
}
//?Since?the?dialog?has?been?closed?return?FALSE?so?that?we?exit?the
//??application?rather?than?start?the?application‘s?message?pump.
return?FALSE;
}
#include“stdio.h“
#include“stdlib.h“
#include“math.h“
#define?OK?1
#define?FALSE?0
#define?TURE?1
#define?NULL?0
#define?pi?3.14
Status?BTree::CreateBiTree(BiTree?&Tchar?*chint?&i)
{
//按先序次序輸入二叉樹中結點的值(一個字符),空格表示空樹,
//構造二叉鏈表表示的二叉樹?T。
if(ch[i]!=‘\0‘){
if(ch[i]==‘#‘){
i++;
T=NULL;
}
else{
if(!(T=(BiTNode?*)malloc(sizeof(BiTNode))))
exit(OVERFLOW);
T->data=ch[i]; //生成根節點
i++;
CreateBiTree(T->lchildchi); //構造左子
CreateBiTree(T->rchildchi); //構造右子樹
}//else
}//?if
return?OK;
}//?CreateBiTreee
void?BTree::DPreOrderTraverse(BiTree?TCString?&cstr)
{
//前序遍歷二叉樹的遞歸算法,
//對每個節點元素進行輸出
if(T){
cstr+=T->data;??????????????????????//先訪問根節點
DPreOrderTraverse(T->lchildcstr); //在線序遍歷左子樹
DPreOrderTraverse(T->rchildcstr); //最后遍歷右子樹
}
}//?PreOrderTraverse
void?BTree::DInOrderTraverse(BiTr
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-11-22?14:14??Binarytree\
?????文件???????22044??2013-11-22?13:21??Binarytree\Binarytree.aps
?????文件????????1732??2013-11-22?14:14??Binarytree\Binarytree.clw
?????文件????????5887??2013-11-22?14:14??Binarytree\Binarytree.cpp
?????文件????????4235??2013-11-21?19:33??Binarytree\Binarytree.dsp
?????文件?????????528??2013-11-24?22:33??Binarytree\Binarytree.dsw
?????文件????????2925??2013-11-22?14:04??Binarytree\Binarytree.h
?????文件???????????0??2013-11-24?22:33??Binarytree\Binarytree.ncb
?????文件???????48640??2013-11-24?22:33??Binarytree\Binarytree.opt
?????文件????????2064??2013-11-22?14:13??Binarytree\Binarytree.plg
?????文件????????6268??2013-11-22?00:43??Binarytree\Binarytree.rc
?????文件????????7297??2013-11-22?14:12??Binarytree\BinarytreeDlg.cpp
?????文件????????1632??2013-11-21?23:31??Binarytree\BinarytreeDlg.h
?????目錄???????????0??2013-11-24?22:33??Binarytree\Debug\
?????文件?????5350400??2013-11-22?14:13??Binarytree\Debug\Binarytree.bsc
?????文件??????114790??2013-11-22?14:13??Binarytree\Debug\Binarytree.exe
?????文件??????209600??2013-11-22?14:13??Binarytree\Debug\Binarytree.ilk
?????文件???????25423??2013-11-22?14:13??Binarytree\Debug\Binarytree.obj
?????文件?????6875720??2013-11-21?19:08??Binarytree\Debug\Binarytree.pch
?????文件??????402432??2013-11-22?14:13??Binarytree\Debug\Binarytree.pdb
?????文件????????3324??2013-11-22?00:43??Binarytree\Debug\Binarytree.res
?????文件???????????0??2013-11-22?14:13??Binarytree\Debug\Binarytree.sbr
?????文件???????39049??2013-11-22?14:12??Binarytree\Debug\BinarytreeDlg.obj
?????文件???????????0??2013-11-22?14:12??Binarytree\Debug\BinarytreeDlg.sbr
?????文件??????105583??2013-11-21?19:08??Binarytree\Debug\StdAfx.obj
?????文件?????1366565??2013-11-21?19:08??Binarytree\Debug\StdAfx.sbr
?????文件??????205824??2013-11-22?14:14??Binarytree\Debug\vc60.idb
?????文件??????372736??2013-11-22?14:13??Binarytree\Debug\vc60.pdb
?????文件????????3651??2013-11-21?18:49??Binarytree\ReadMe.txt
?????文件?????????212??2013-11-21?18:49??Binarytree\StdAfx.cpp
?????文件????????1054??2013-11-21?18:49??Binarytree\StdAfx.h
............此處省略4個文件信息
- 上一篇:基于VC++ MFC通訊錄
- 下一篇:課程設計車票管理系統
評論
共有 條評論