| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 600 人关注过本帖
标题:拓扑排序
只看楼主 加入收藏
liyf绿茶
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-9-18
收藏
 问题点数:0 回复次数:3 
拓扑排序
#include"iostream.h"

#define MaxNum 100;
typedef char VertexType;
typedef int EdgeType;
typedef struct {
    VertexType vexs[MaxNum];
    EdgeType edges[MaxNum][MaxNum];
    int n,e;//定点数和边数
}MGraph;

typedef enum{False,True}Boolean;

void CreateM()
{
    MGraph * G;
    int i,j;
    cout<<"Input the number of the number:";
    cin>>G->n;
    for(i=0;i<G->n;i++)
        for(j=0;j<G->n;j++)
            G->edges[i][j]=0;
    cout<<"Input the nodes of edges:";
    do{
        cin>>i;
        cout<<" ";
        cin>>j;
        G->edges[i][j]=1;
    }while((i!=-1)&&(j!=-1))
}

void TopSort()
{
    MGraph *G;
    int i,j;
    int degree[MaxNum];
    Boolean visited[MaxNum];
    Boolean flag=True;
    cout<<endl<<"The Toplogical Order as follow:";
    for(i=0;i<G->n;i++)
    {
        visited[i]=False;//初始化访问位
        degree[i]=0;
    }

    while(flag==True)
    {
        
        for(i=0;i<G->n;i++)
            for(j=0;j<G->n;j++)
                degree[i]= G->edges[j][i]+degree[i];//计算每个顶点的入度
        i=0;
        while((i<G->n)&&(degree[i]!=0||visited[i]==True))i++;//入度为0的先出

        if(i<G->n)
        {
            cout<<" "<<i;//每个顶点以空格隔开
            visited[i]=True;
            for(j=0;j<G->n;j++)
            {
                G->edges[i][j]=0;
                degree[j]=0;
            }
        }
        else
            flag=False;
        
    }

}
        
void main()
{
    CreateM();
    TopSort();
}

我用的是VC6.0。编译后总是报
--------------------Configuration: Topsort - Win32 Debug--------------------
Compiling...
top.cpp
E:\备份c盘\shuju\Topsort\top.cpp(8) : error C2143: syntax error : missing ']' before ';'
E:\备份c盘\shuju\Topsort\top.cpp(8) : error C2059: syntax error : ']'
E:\备份c盘\shuju\Topsort\top.cpp(8) : error C2238: unexpected token(s) preceding ';'
E:\备份c盘\shuju\Topsort\top.cpp(9) : error C2143: syntax error : missing ']' before ';'
E:\备份c盘\shuju\Topsort\top.cpp(9) : error C2059: syntax error : ']'
E:\备份c盘\shuju\Topsort\top.cpp(9) : error C2238: unexpected token(s) preceding ';'
E:\备份c盘\shuju\Topsort\top.cpp(9) : error C2059: syntax error : ']'
E:\备份c盘\shuju\Topsort\top.cpp(9) : error C2238: unexpected token(s) preceding ';'
E:\备份c盘\shuju\Topsort\top.cpp(23) : error C2109: subscript requires array or pointer type
E:\备份c盘\shuju\Topsort\top.cpp(23) : error C2106: '=' : left operand must be l-value
E:\备份c盘\shuju\Topsort\top.cpp(29) : error C2109: subscript requires array or pointer type
E:\备份c盘\shuju\Topsort\top.cpp(29) : error C2106: '=' : left operand must be l-value
E:\备份c盘\shuju\Topsort\top.cpp(31) : error C2143: syntax error : missing ')' before '}'
E:\备份c盘\shuju\Topsort\top.cpp(31) : error C2143: syntax error : missing ';' before ')'
E:\备份c盘\shuju\Topsort\top.cpp(31) : error C2143: syntax error : missing ';' before ')'
E:\备份c盘\shuju\Topsort\top.cpp(37) : error C2143: syntax error : missing ']' before ';'
E:\备份c盘\shuju\Topsort\top.cpp(37) : error C2143: syntax error : missing ';' before ']'
E:\备份c盘\shuju\Topsort\top.cpp(38) : error C2143: syntax error : missing ']' before ';'
E:\备份c盘\shuju\Topsort\top.cpp(38) : error C2143: syntax error : missing ';' before ']'
E:\备份c盘\shuju\Topsort\top.cpp(52) : error C2109: subscript requires array or pointer type
E:\备份c盘\shuju\Topsort\top.cpp(62) : error C2109: subscript requires array or pointer type
E:\备份c盘\shuju\Topsort\top.cpp(62) : error C2106: '=' : left operand must be l-value
Error executing cl.exe.

top.obj - 22 error(s), 0 warning(s)
我找不到问题出现在哪,请高手指点!!!急急
搜索更多相关主题的帖子: 拓扑 
2008-09-18 09:49
liyf绿茶
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-9-18
收藏
得分:0 
我找过了 并没有少";"或着"]" 我急急 请大家帮我看看 谢谢
2008-09-18 09:51
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
这个自己改改啊。。很死板的东西。。

学习需要安静。。海盗要重新来过。。
2008-09-18 10:39
ma3587
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2008-6-17
收藏
得分:0 
#define 不加分号吧
2008-09-18 11:04
快速回复:拓扑排序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024372 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved