bool insert_vertex(ListGraph *G, VertexType v){
if(locate_vertex(G,v) != -1){
return false;
}
if(G -> vexnum == MAX_VERTEX_NUM){
return false;
}
VNode temp ;
temp.data = v;
temp.firstarc = NULL;
G -> vertex[G -> vexnum] = temp;
G -> vexnum++;
return true;
}
bool insert_arc(ListGraph *G, VertexType v, VertexType w){
if(locate_vertex(G,v) == -1 || locate_vertex(G,w) == -1){
return false;
}
ArcNode *temp, *p, *q, no_sense;
p = &no_sense;
p -> adjvex = w;
p -> nextarc = NULL;
int i = 0;
int j = 0;
i = locate_vertex(G,v);
j = locate_vertex(G,w);
temp = (G -> vertex[i].firstarc);
if(temp == NULL){
G -> vertex[i].firstarc = p;
p -> nextarc = NULL;
return true;
}
while(temp -> nextarc != NULL && temp -> adjvex != w){
temp = temp -> nextarc;
}
if(temp -> adjvex == p ->adjvex){
return false;
}
if(temp -> nextarc == NULL){
temp -> nextarc = p;
p -> nextarc = NULL;
}
if(G -> type ==UDG){
i = locate_vertex(G,w);
if(locate_vertex(G,w) == -1){
return false;
}
temp = (G -> vertex[v].firstarc);
if(temp == NULL){
G -> vertex[i].firstarc = p;
p -> nextarc = NULL;
return true;
}
while(temp -> nextarc != NULL && temp -> adjvex != w){
temp = temp -> nextarc;
}
if(temp -> adjvex == p ->adjvex){
return false;
}
if(temp -> nextarc == NULL){
temp -> nextarc = p;
p -> nextarc = NULL;
}
}
G -> arcnum++;
return true;
}