第一篇:鄰接矩陣構造函數算法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; } } //邊依附的兩個頂點的序號 //置有邊標志 1.確定圖的頂點個數和邊的個數; 2.輸入頂點信息存儲在一維數組vertex中; 3.初始化鄰接矩陣; 4.依次輸入每條邊存儲在鄰接矩陣arc中; 4.1 輸入邊依附的兩個頂點的序號i, j; 4.2 將鄰接矩陣的第i行第j列的元素值置為1; 4.3 將鄰接矩陣的第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