Skip to content

Commit

Permalink
add graph_is_adjacent
Browse files Browse the repository at this point in the history
  • Loading branch information
weijieblog committed Jun 2, 2016
1 parent 86a645d commit 994b42f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
13 changes: 13 additions & 0 deletions graph/graph_is_adjacent.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "graph.h"

int graph_is_adjacent(const Graph *graph, const void *data1, const void *data2) {
ListElm *element;
for (element = list_head(&graph->adjlists); element != NULL; element = list_next(element)) {
if (graph->match(data1, ((AdjList *)list_data(element))->vertex))
break;
}
if (element == NULL)
return 0;

return set_is_member(&((AdjList *)list_data(element))->adjacent, data2);
}
4 changes: 4 additions & 0 deletions graph/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ int main (int argc, char **argv) {
testGraph1->ecount == 1 &&
*(int *)testPtr2 == 2);

testPtr2 = &testData2;
printf("'graph_is_adjacent' is pass ? %d \n", graph_is_adjacent(testGraph1, testPtr1, testPtr2));



testPtr2 = &testData2;
graph_remove_edge(testGraph1, testPtr1, &testPtr2);
Expand Down
9 changes: 8 additions & 1 deletion graph/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ setObjects = ../set/set_init.o \
../set/set_remove.o \
../set/set_union.o

graphObjects = main.o graph_init.o graph_destory.o graph_insert_vertex.o graph_insert_edge.o graph_remove_vertex.o graph_remove_edge.o
graphObjects = main.o \
graph_init.o \
graph_destory.o \
graph_insert_vertex.o \
graph_insert_edge.o \
graph_remove_vertex.o \
graph_remove_edge.o \
graph_is_adjacent.o

objects = $(listsObjects) $(setObjects) $(graphObjects)

Expand Down

0 comments on commit 994b42f

Please sign in to comment.