#include<stdio.h>
#include<conio.h>
struct GNode{
struct gnode* nextnode;
struct gnode* arcptr;
int Visited;
}
typedef struct GNode* Grnd;
struct ArcNode{
struct arcnode* nextarc;
struct acrnode* ndptr;
}
typedef struct ArcNode* Arc;
Grnd getGraphNode(){
Grnd NewNode=(Grnd)malloc(sizeof(struct GNode));
NewNode->nextnode=NULL;
NewNode->arcptr=NULL;
return NewNode;
}
Arc getArcNode(){
Arc NewArc=(Arc)malloc(sizeof(struct ArcNode));
NewArc->nextarc=NULL;
NewArc->ndptr=NULL;
return NewArc;
}
void join(Grnd *GNode1,Grnd *GNode2){
Arc NewArc=getArcNode();
NewArc->ndptr=(*GNode2);
NewArc->nextarc=(*GNode1)->arcptr;
(*GNode1)->arcptr=NewArc;
}
Grnd addNode(Grnd *Graph){
Grnd NewNode=getGraphNode();
if((*Graph)==NULL){
(*Graph)=NewNode;
return NewNode;
}
while((*Graph)->nextnode!=NULL)
Graph=Graph->nextnode;
(*Graph)->nextnode=NewNode;
return NewNode;
}
考虑到上面的C代码:我担心当我调用join
函数来加入两个图节点时,它真的会加入它们吗?因为一旦程序超出 , 的范围join
,NewArc
就不存在了。因此,当我在创建图表后尝试找到给定节点的所有相邻节点时,我能做到吗?为什么?