引用参数需要左值 比如下列代码中出现的问题

#include<stdio.h>
#include<string.h>
#include<malloc.h>
int mark[10060];
int zhan[10060];
int di,ding;
int k,m,bg,u,v;
struct node
{
    int data;
    struct node *firstarc;
};
struct tu
{
    struct node dingdian[200];
    int bian;
    int dingdiangeshu;
};
void creat(struct tu * &G)
{

    int i;
    for(i=0;i<=k-1;i++)
    {
        G->dingdian[i].data=i;
        G->dingdian[i].firstarc=NULL;
    }

    while(m--)
    {
        // printf("111\n");
        scanf("%d%d",&u,&v);
        struct node *p;
        p=(struct node *)malloc(sizeof(struct node));
        p->data=u;
        p->firstarc=NULL;
        struct node *q;
        q=&G->dingdian[v];
        while(q->firstarc) q=q->firstarc;
        p->firstarc=q->firstarc;
        q->firstarc=p;

        p=(struct node *)malloc(sizeof(struct node));
        p->data=v;
        p->firstarc=NULL;
        q=&G->dingdian[u];
        while(q->firstarc) q=q->firstarc;
        p->firstarc=q->firstarc;
        q->firstarc=p;

    }
}
void bfs(struct tu *G)
{
    di=0;ding=0;
    mark[bg]=1;
    zhan[ding++]=bg;
    int count=0;
    while(di!=ding)
    {
        int ss;
        ss=zhan[di];
        di++;

        if(count==0) {printf("%d",ss);count++;}
        else {printf(" %d",ss);count++;}
        struct node *p=&G->dingdian[ss];
        while(p)
        {
            if(mark[p->data]==0)  //未访问过该节点
            {
                zhan[ding++]=p->data;
                mark[p->data]=1;
            }
            p=p->firstarc;
        }
    }
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {

        scanf("%d%d%d",&k,&m,&bg);
        memset(mark,0,sizeof(mark));
        struct tu G;
        struct tu *T;
        T=NULL;
        creat(T);   这里
        creat(&G);   和这里
        bfs(&G);
        printf("\n");
    }
}
为什么传递参数时第一个可以,第二个不可以,T和&G不都相当于一个 struct tu *的类型吗
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值