标题:各位大神求助 十字链表存储图的问题
只看楼主
guxingyushan
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-5-19
结帖率:100%
已结贴  问题点数:20 回复次数:1 
各位大神求助 十字链表存储图的问题
#define maxnode 30
#include <stdio.h>
#include <stdlib.h>

typedef struct arc
{
    int tailvex;
    int headvex;
//    int info;
    struct arc *hlink;
    struct arc *tlink;
}arctype;

typedef struct vertex
{
    int data;
    struct arctype *firstin;
    struct arctype *firstout;
}vertextype;

typedef vertextype graph[maxnode];

int findvertex(int v,graph digraph)
 {
     int k;
     for (k=0;k<maxnode;k++)
     {
         if (digraph[k].data==v)
             return k;
     }
 }
 
int main(void)
{
    int i,j,n,e,k;
    int v1,v2;
    arctype *p,*q;
    graph digraph;
    printf("输入有向图顶点数和边数\n");
    scanf("%d%d",&n,&e);
    printf("输入顶点数据:\n");
    for (k=0;k<n;k++)
    {
        scanf("%d",&digraph[k].data);
        digraph[k].firstin=NULL;
        digraph[k].firstout=NULL;
     }
    printf("输入边的头结点和尾结点:\n");
    for (k=0;k<e;k++)
    {
        scanf("%d%d",&v1,&v2);
        p=(arctype*)malloc(sizeof(arctype));
        i=findvertex(v1,digraph);
        j=findvertex(v2,digraph);
        p->tailvex=v1;
        p->tlink=digraph[i].firstout;
        digraph[i].firstout=p;
        p->headvex=v2;
        p->hlink=digraph[j].firstin;
        digraph[j].firstin=p;
    }
    printf("有向图的结构为:\n");
    for (k=0;k<n;k++)
    {
        printf("%d.",k+1);
        v1=digraph[k].data;
        printf("%d",v1);
        p=digraph[i].firstout;
        while (p=!NULL)
        {
            v2=p->headvex;
            printf("-->%d",v2);
            p=p->hlink;
        }
        printf("\n");
        
        printf("%d.",k+1);
        v1=digraph[k].data;
        printf("%d",v1);
        p=digraph[k].firstin;
        while (p=!NULL)
        {
            v2=p->tailvex;
            printf("<--%d",v2);
            p=p->tlink;
        }
        printf("\n");
     }
    return 0;
}
提醒[Warning] assignment from incompatible pointer type 指针有什么问题吗?求助求助!
搜索更多相关主题的帖子: include 
2016-05-19 22:29
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:20 
typedef struct arc
{
    ……
}arctype;
后,arctype就是struct arc,struct arc就是arctype
请问你代码中的 struct arctype * 是个什么意思?!

其它的 != 写成 =! 等就不多说了
收到的鲜花
  • guxingyushan2016-05-20 09:50 送鲜花  2朵   附言:啊,初学者没有注意这个问题...谢谢大神1
2016-05-20 08:30



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-465034-1-1.html




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

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