int shortPathMain()
{
    int i,j;
    int cost[][7]= {        //将路径图以矩阵形式表示
        {0,20,50,30,200,200,200},
        {200,0,25,200,200,70,200},
        {200,200,0,40,25,50,200},
        {200,200,200,0,55,200,200},
        {200,200,200,200,0,10,70},
        {200,200,200,200,200,0,50},
        {200,200,200,200,200,200,0}
    };
    cout<<"带权的有向图如下所示:"<<endl;
    cout<<"     ";
    for(i=0; i<7; i++) cout<<"v"<<i+1<<"   ";
    cout<<endl;
    for(i=0; i<7; i++)
    {
        cout<<"v"<<i+1<<"   ";
        for(j=0; j<7; j++)
            cout<<left<<setw(5)<<cost[i][j];
        cout<<endl;
    }
    int dist[7];
    cout<<"单源点最短路径算法运行结果:"<<endl;
    ShortestPath(0,cost,dist,6);//单源点最短路径

    cout<<endl<<"每对结点间的最短路径算法运行结果:"<<endl;
    AllPath(cost,6);//每对结点间的最短路径

    system("pause");
    return 1;
}
Beispiel #2
0
void main()
{
	BTNode *b;
	ElemType path[MaxSize],longpath[MaxSize];
	int i,longpathlen=0;
	CreateBTNode(b,"A(B(D,E(H(J,K(L,M(,N))))),C(F,G(,I)))"); 
	printf("二叉树b:");DispBTNode(b);printf("\n");
	printf("b的叶子节点:");DispLeaf(b);printf("\n");
	printf("AllPath:\n");AllPath(b);
	printf("AllPath1:\n");AllPath1(b,path,0);
	LongPath(b,path,0,longpath,longpathlen);
	printf("第一条最长逆路径长度:%d\n",longpathlen);
	printf("第一条最长逆路径:");
	for (i=longpathlen-1;i>=0;i--)
		printf("%c ",longpath[i]);
	printf("\n");
	DestroyBTNode(b);
}
Beispiel #3
0
int main()
{
	int gd=DETECT,gm;
	initgraph(&gd,&gm,"c://TC/bgi");
	setlinestyle(SOLID_LINE,1,3);
	GetVertices();
	GetEdges();
	Redraw(adj,0);
	AllPath();
       //	Redraw(A,0);
     //	Redraw(A);
	//gotoxy(2,4);

	//printf("Minimum Cost of this spaning tree is : %d",mstcost);

	getch();

	closegraph();
	return 0;
}