c语言有3个警告,运行不出,帮忙看看
#include<iostream.h>#include<stdio.h>#include<malloc.h>typedefstructEdgenode{intadjve...
#include<iostream.h>
#include <stdio.h>
#include <malloc.h>
typedef struct Edgenode{
int adjvex; //邻接点
Edgenode* next; // 指向边结点的指针
}*link,Edgenode;
link Lnode(int adjvex,link next){
link m;
m=(link)malloc(sizeof*m);
m->adjvex;
m->next=next;
return m;
}
typedef struct {
int n; //点数
int eg; //边数
link *adj; //邻接表数组
}Lgraph,*Graph;
/////////////创建有向图(无边)////////////////
Graph Graphinit(int n,Edgenode elink){
int i;
Graph Gr=(Graph)malloc(sizeof*Gr);
Gr->n=n;
Gr->eg=0;
int num=elink.adjvex;
int num1=sizeof(link);
Gr->adj=(link*)malloc((num+1)*num1);
for(i=0;i<=Gr->eg||elink.adjvex;i++)Gr->adj[i]=0;
return Gr;
}
///////////////判断边是否存在///////////////
int Exist(int i,int j,Graph Gr){
link p;
if(i<1||j<1||i>Gr->n)return 0;
p=Gr->adj[i];
while(p&&p->adjvex!=j)p=p->next;
if(p)return 1;
else return 0;
}
///////////////插入边//////////////////////
int Graphadd(int i,int j,Graph Gr){
if(i<1||j<1||i>Gr->n||j>Gr->n||Exist(i,j,Gr))return 0;
Gr->adj[i]=Lnode(j,Gr->adj[i]);
Gr->eg++;
return 1;
}
/////////创建图的邻接表////////////////////
Graph Gr(Graph Gra){
cout<<"请输入点数和边数"<<endl;
int n,egde;
Edgenode temlink;
cin>>n,egde;
Graphinit(n,temlink);
for(int h=0;h<egde;h++){
int i=0,j=0;
cout<<"请输入边的两端点"<<endl;
cin>>i>>j;
Graphadd(i,j,Gra);
}
return Gra;
}
void main(){
Graph G;
Gr(G);
}
C:\Program Files\Microsoft Visual Studio\MyProjects\实习2\实习.cpp(57) : warning C4700: local variable 'temlink' used without having been initialized
C:\Program Files\Microsoft Visual Studio\MyProjects\实习2\实习.cpp(58) : warning C4700: local variable 'egde' used without having been initialized
C:\Program Files\Microsoft Visual Studio\MyProjects\实习2\实习.cpp(69) : warning C4700: local variable 'G' used without having been initialized
大侠们,帮忙看看.... 展开
#include <stdio.h>
#include <malloc.h>
typedef struct Edgenode{
int adjvex; //邻接点
Edgenode* next; // 指向边结点的指针
}*link,Edgenode;
link Lnode(int adjvex,link next){
link m;
m=(link)malloc(sizeof*m);
m->adjvex;
m->next=next;
return m;
}
typedef struct {
int n; //点数
int eg; //边数
link *adj; //邻接表数组
}Lgraph,*Graph;
/////////////创建有向图(无边)////////////////
Graph Graphinit(int n,Edgenode elink){
int i;
Graph Gr=(Graph)malloc(sizeof*Gr);
Gr->n=n;
Gr->eg=0;
int num=elink.adjvex;
int num1=sizeof(link);
Gr->adj=(link*)malloc((num+1)*num1);
for(i=0;i<=Gr->eg||elink.adjvex;i++)Gr->adj[i]=0;
return Gr;
}
///////////////判断边是否存在///////////////
int Exist(int i,int j,Graph Gr){
link p;
if(i<1||j<1||i>Gr->n)return 0;
p=Gr->adj[i];
while(p&&p->adjvex!=j)p=p->next;
if(p)return 1;
else return 0;
}
///////////////插入边//////////////////////
int Graphadd(int i,int j,Graph Gr){
if(i<1||j<1||i>Gr->n||j>Gr->n||Exist(i,j,Gr))return 0;
Gr->adj[i]=Lnode(j,Gr->adj[i]);
Gr->eg++;
return 1;
}
/////////创建图的邻接表////////////////////
Graph Gr(Graph Gra){
cout<<"请输入点数和边数"<<endl;
int n,egde;
Edgenode temlink;
cin>>n,egde;
Graphinit(n,temlink);
for(int h=0;h<egde;h++){
int i=0,j=0;
cout<<"请输入边的两端点"<<endl;
cin>>i>>j;
Graphadd(i,j,Gra);
}
return Gra;
}
void main(){
Graph G;
Gr(G);
}
C:\Program Files\Microsoft Visual Studio\MyProjects\实习2\实习.cpp(57) : warning C4700: local variable 'temlink' used without having been initialized
C:\Program Files\Microsoft Visual Studio\MyProjects\实习2\实习.cpp(58) : warning C4700: local variable 'egde' used without having been initialized
C:\Program Files\Microsoft Visual Studio\MyProjects\实习2\实习.cpp(69) : warning C4700: local variable 'G' used without having been initialized
大侠们,帮忙看看.... 展开
4个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询