第一篇:中序线索链表构造函数算法InThrBiTree
template
InThrBiTree::InThrBiTree(ThrNode
Creat(root);
pre=NULL;
ThrBiTree(root);
}
template
void InThrBiTree ::Creat(ThrNode
cin>>ch;
if(ch=='# ')root=NULL;//建立一棵空树else {
root=new ThrNode
}
template
void InThrBiTree ::ThrBiTree(ThrNode
if(root==NULL)return;
ThrBiTree(root->lchild);
if(!root->lchild){//对root的左指针进行处理
root->ltag=1;
root->lchild=pre;//设置pre的前驱线索
}
if(!root->rchild)root->rtag=1;//对root的右指针进行处理if(pre->rtag==1)pre->rchild=root;//设置pre的后继线索pre=root;
ThrBiTree(root->rchild);
}
第二篇:邻接矩阵构造函数算法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; } } //边依附的两个顶点的序号 //置有边标志 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;//输入边所依附的两个顶点的序号s=new ArcNode;s->adjvex=j;//生成一个边表结点ss->next=adjlist[i].firstedge;//将结点s插入到结点i的边表的表头 adjlist[i].firstedge=s; } } template BiTree ::BiTree(BiNode creat(root); } template void BiTree ::Creat(BiNode cin>>ch; if(ch=='# ')root=NULL;//建立一棵空树else { root=new BiNode Creat(root->lchild);//递归建立左子树Creat(root->rchild);//递归建立右子树} }第三篇:二叉排序树构造函数算法BISORTTREE
第四篇:邻接表构造函数算法ALGraph
第五篇:二叉树的构造函数算法BiTree