1 2 3 4 5
106 5
VC6.0VC2010
1
2;70
3
1.; 2.; 3.; 4.;
C
DATA STRUCTURE WITH C William Ford,William Topp
: : : 2
:
:
1
2:
:
1.: 1
2
3
2.
3. :
1
2
4.
5.
6.
7.
25 :
1Microsoft VC2015 :
2D Test4;
3Filenew
4Win32
5Project nameExp4LocationD:Test4
6OK
6 1
includeiostream includestring using namespace std;
template class T
struct BiNode
T data;
BiNodeT lchild, rchild; ;
template class T class BiTree
public:
BiTree ;
BiTreevoid;
BiNodeT Getroot;
void PreOrderBiNodeT root; void InOrderBiNodeT root; void PostOrderBiNodeT root; void LeverOrderBiNodeT root;
private:
BiNodeT root;BiNodeT Creat ;
void ReleaseBiNodeT root;
::
:: :
templateclass T BiTreeT::BiTree
thisrootCreat ;
;
:
:
::
:
templateclass T BiTreeT::BiTreevoid
Releaseroot;
:
:
:: :
templateclass T
BiNodeT BiTreeT::Getroot
return root;
:
:
:
: :
templateclass T
void BiTreeT::PreOrderBiNodeT root
ifrootNULL return; else
coutrootdata ; PreOrderrootlchild;
PreOrderrootrchild;
:
:
:
: :
template class T
void BiTreeT::InOrder BiNodeT root
if rootNULL return; else
InOrderrootlchild; coutrootdata ; InOrderrootrchild;
root
root
:
:
:
: :
template class T
void BiTreeT::PostOrderBiNodeT root
if rootNULL return;else
PostOrderrootlchild; PostOrderrootrchild; coutrootdata ;
root root
:
:
:
: :
template class T
void BiTreeT::LeverOrderBiNodeT root
1 2 BiNodeT
3 root
root ;
while
q;
q ;
q ;q ;
:
: ch;
:,:
:
template class T
BiNodeT BiTreeT::Creat
BiNodeT root;
T ch; coutendl; cinch;
if ch rootNULL;
else
rootnew BiNodeT; rootdatach; rootlchildCreat ; rootrchildCreat ;
return root;
:
:
::
:
templateclass T
void BiTreeT::ReleaseBiNodeT root
if root ! NULL Releaserootlchild; Releaserootrchild; delete root;
void main
BiTreestring bt;BiNodestring rootbt.Getroot ;
cout endl; bt.PreOrderroot;
coutendl; cout endl; bt.InOrderroot;
coutendl; cout endl; bt.PostOrderroot;
coutendl; cout endl; bt.LeverOrderroot;
coutendl;
systempause;
: ABDC
25 :
1Microsoft VC6.0 :
2DTest4 Test4; 3Filenew
4Win32 ConsoleApplication
5Project nameInThrBiTreeLocationD:Test4
6OK
7Finish
8Filenew
9CC Header File .hInThrBiTree 10OK InThrBiTree.h12Filenew
13CC Source File .cppInThrBiTree,OK InThrBiTree.cpp
14FilenewCC Source File .cpp inthrbitreemain, OKinthrbitreemain.cpp
1 inthrbitree.h ifndef INTHRBITREEH
define INTHRBITREEH
enum flag Child, Thread;Child0Thread1
template class T struct ThrNode
T data;
ThrNodeT lchild, rchild; flag ltag, rtag;
;
template class T class InThrBiTree
public:
InThrBiTree ;
InThrBiTree ;
ThrNodeT Getroot ; ThrNodeT NextThrNodeT p; void InOrderThrNodeT root;
private:
ThrNodeT root;ThrNodeT Creat ;
void ThrBiTreeThrNodeT root;void ReleaseThrNodeT root;
; endif
2 inthrbitree.cpp
includeiostream includestring includeinthrbitree.h using namespace std;
::
:: :
template class T InThrBiTreeT::InThrBiTree
ThrNodeT preNULL;
thisrootCreat ; ThrBiTreeroot;
p
:
:
::
:
template class T InThrBiTreeT::InThrBiTreevoid
Releaseroot;
:
:
:: :
template class T
ThrNodeT InThrBiTreeT::Getroot
return root;
:
:
:p
: p:
template class T
ThrNodeT InThrBiTreeT::NextThrNodeT p
ThrNodeT q;
if prtagThread qprchild;1 else
qprchild;
while qltagChild
qqlchild;
return q;
:
:
:
: :
template class T
void InThrBiTreeT::InOrderThrNodeT root
ThrNodeT proot;
if rootNULL return; while pltagChild
pplchild;
coutpdata ; while prchild!NULL
pNextp;
coutpdata ;
coutendl;
p
p
:
:
:,: :
template class T
ThrNodeT InThrBiTreeT::Creat
ThrNodeT root;
T ch; coutendl; cinch;
if ch rootNULL;
else
rootnew ThrNodeT;
rootdatach; rootltagChild; rootrtagChild; rootlchildCreat ; rootrchildCreat ;
return root;
:
:
:
: :
template class T
void InThrBiTreeT::ThrBiTreeThrNodeT root
if rootNULL return; ThrBiTreerootlchild; if !rootlchild
rootltagThread; rootlchildpre;
root
pre
if !rootrchild rootrtagThread; ifpre ! NULL
root pre
if prertagThread
preroot; ThrBiTreerootrchild;
prerchildroot;
:
:
::
:
templateclass T
void InThrBiTreeT::ReleaseThrNodeT root
if root!NULL
Releaserootlchild;Releaserootrchild;
delete root;
3 inthrbitreemain.cpp includeiostream
includestring includeinthrbitree.cpp using namespace std; ThrNodestring pre; void main
InThrBiTreestring inbt; ThrNodestring pinbt.Getroot ;coutendl;
inbt.InOrderp;
systempause;
4ABDC
1. 2. 3.
Reviews
There are no reviews yet.