引用参数需要左值 比如下列代码中出现的问题
来源:互联网 发布:美国钻井平台数据公布 编辑:程序博客网 时间:2024/06/05 20:07
#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 *的类型吗
#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
- 引用参数需要左值 比如下列代码中出现的问题
- jsf 中引用 a4j 出现的问题
- 引用类型参数的初始化及可能出现的问题
- “非常量引用的初始值必须为左值”问题
- SpriteBuilder代码中弱引用(weak)需要注意的地方
- 左值引用的限制
- 代码风格中需要注意的问题
- 在OkHttp的使用过程中出现下列问题Picasso detected an unsupported OkHttp on the classpath.
- 在OkHttp的使用过程中出现下列问题Picasso detected an unsupported OkHttp on the classpath.
- 在OkHttp的使用过程中出现下列问题Picasso detected an unsupported OkHttp on the classpath.
- 137、写出下列代码的输出内容,函数指针问题
- 参数为引用时需要注意的
- C++函数参数传递的一大利器——引用(左值)
- Linux环境下配置出现下列问题
- 代码中出现的奇怪问题原因
- 关于引用js文件中出现乱码问题的解决方案
- [第二节]C++ 引用 函数调用作为左值 用const限定引用 返回堆中变量的引用
- .net中引用传递对象作为参数传递的问题
- angulasJS 指令范例
- js数组常用方法总结
- 利用javadoc定制自己的接口文档(一)
- 对比JAVA学习PHP系列:函数
- Affinity Propagation
- 引用参数需要左值 比如下列代码中出现的问题
- JDBC连接数据库的几种方法与简单解析
- Linux内核中的内存管理浅谈 .
- C++:智能指针_auto_ptr_vs版本
- ORA-01017 invalid username/password;logon denied" (密码丢失解决方案)
- ImageSeclect和Glide实现从图库选择或者拍照设置头像
- linux进程地址空间--vma的基本操作
- 京城游戏人-Day17: 如何进行 iOS 的内购沙盒测试?
- 数据结构上机实验之二分查找