第一篇:中序線索鏈表構(gòu)造函數(shù)算法InThrBiTree
template
InThrBiTree::InThrBiTree(ThrNode
Creat(root);
pre=NULL;
ThrBiTree(root);
}
template
void InThrBiTree ::Creat(ThrNode
cin>>ch;
if(ch=='# ')root=NULL;//建立一棵空樹(shù)else {
root=new ThrNode
}
template
void InThrBiTree ::ThrBiTree(ThrNode
if(root==NULL)return;
ThrBiTree(root->lchild);
if(!root->lchild){//對(duì)root的左指針進(jìn)行處理
root->ltag=1;
root->lchild=pre;//設(shè)置pre的前驅(qū)線索
}
if(!root->rchild)root->rtag=1;//對(duì)root的右指針進(jìn)行處理if(pre->rtag==1)pre->rchild=root;//設(shè)置pre的后繼線索pre=root;
ThrBiTree(root->rchild);
}
第二篇:鄰接矩陣構(gòu)造函數(shù)算法MGraph
template
MGraph::MGraph(T a[ ], int n, int e){
vertexNum=n;arcNum=e;
for(i=0;i vertex[i]=a[i]; for(i=0;i cin>>i>>j; arc[i][j]=1; arc[j][i]=1; } } //邊依附的兩個(gè)頂點(diǎn)的序號(hào) //置有邊標(biāo)志 BiSortTree::BiSortTree(int r[ ], int n){ for(i=0;i { s=new BiNode InsertBST(root, s); } } template ALGraph::ALGraph(T a[ ], int n, int e){ vertexNum=n;arcNum=e; for(i=0;i adjlist[i].vertex=a[i]; adjlist[i].firstedge=NULL;} for(k=0;k cin>>i>>j;//輸入邊所依附的兩個(gè)頂點(diǎn)的序號(hào)s=new ArcNode;s->adjvex=j;//生成一個(gè)邊表結(jié)點(diǎn)ss->next=adjlist[i].firstedge;//將結(jié)點(diǎn)s插入到結(jié)點(diǎn)i的邊表的表頭 adjlist[i].firstedge=s; } } template BiTree ::BiTree(BiNode creat(root); } template void BiTree ::Creat(BiNode cin>>ch; if(ch=='# ')root=NULL;//建立一棵空樹(shù)else { root=new BiNode Creat(root->lchild);//遞歸建立左子樹(shù)Creat(root->rchild);//遞歸建立右子樹(shù)} }第三篇:二叉排序樹(shù)構(gòu)造函數(shù)算法BISORTTREE
第四篇:鄰接表構(gòu)造函數(shù)算法ALGraph
第五篇:二叉樹(shù)的構(gòu)造函數(shù)算法BiTree