| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1244 人关注过本帖
标题:图的拓扑排序问题
只看楼主 加入收藏
wangyinshiwo
Rank: 1
等 级:新手上路
帖 子:75
专家分:0
注 册:2007-11-9
收藏
 问题点数:0 回复次数:1 
图的拓扑排序问题
/* Note:Your choice is C IDE */
#include "stdio.h"
#include<malloc.h>
#define MAX 100
typedef struct edgesnode
{
    int adjvex;
    int value;
    struct edgesnode *next;
}arcnode;
typedef struct vexnode
{
    char data;
    int count;
    arcnode *firsthead;
}headnode;
typedef struct
{
    int n,e;
    headnode adjlist[MAX];
}graphlist;
int creatgraph(graphlist *g)
{
    int i,b,t,w;
    arcnode *p;
    printf("顶点数和边数:");
    scanf("%d%d",&g->n,&g->e);
    for(i=0;i<g->n;i++)
    {
        getchar();
        printf("序号为%d的顶点信息:",i);
        scanf("%c",&g->adjlist[i].data);
        g->adjlist[i].firsthead=NULL;
    }
    for(i=0;i<g->e;i++)
    {
        printf("序号为%d的边=>",i);
        printf("起点号 终点号 权值:");
        scanf("%d%d%d",&b,&t,&w);
        if(b<g->n&&t<g->n&&w>0)
        {
            p=(arcnode *)malloc(sizeof(arcnode));
            p->value=w;p->adjvex=t;
            p->next=g->adjlist[b].firsthead;
            g->adjlist[b].firsthead=p;
        }
        else
        {
            printf("输入错误:");
            return 0;
        }
    }
    return 1;
}
void topsort(headnode adj[],int n)
{
    int i,j;
    int st[MAX],top=0;
    arcnode *p;
    for(i=0;i<n;i++)
    if(adj[i].count==0)
    { top++;st[top]=i; }
    while(top!=0)
    {
        i=st[top];top--;
        printf("%d",i);
        p=adj[i].firsthead;
        while(p)
        {
            j=p->adjvex;
            adj[j].count--;
            if(adj[j].count==0)
            { top++;st[top]=j; }
            p=p->next;
        }
    }
}
void main()
{
    graphlist g;
    headnode adj[MAX];
    creatgraph(&g);
    topsort(adj,g.n);
}
大家帮我看看应该怎么改才能运行。
搜索更多相关主题的帖子: int 拓扑 struct typedef 
2008-06-15 16:08
wangyinshiwo
Rank: 1
等 级:新手上路
帖 子:75
专家分:0
注 册:2007-11-9
收藏
得分:0 
怎么没有人啊!自己给自己顶一个。

抽刀断水水更流,举杯消愁愁更愁。
2008-06-16 23:55
快速回复:图的拓扑排序问题
数据加载中...
 
   



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

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