void main() { GRAPH tu; GraphCreate(&tu); GraphOut(tu); GraphDFS(tu); GraphBFS(tu); }
int main(){ graphADT graph = GraphCreate() ; GraphAddVertex(graph, 'A') ; GraphAddVertex(graph, 'B') ; GraphAddVertex(graph, 'C') ; GraphAddVertex(graph, 'D') ; GraphAddVertex(graph, 'E') ; GraphAddEdge( getVertex(graph, 'A'), getVertex(graph, 'C') ) ; GraphAddEdge( getVertex(graph, 'C'), getVertex(graph, 'D') ) ; GraphAddEdge( getVertex(graph, 'D'), getVertex(graph, 'E') ) ; GraphAddEdge( getVertex(graph, 'B'), getVertex(graph, 'E') ) ; printf("\n Is vertex E reachable from A? : %s \n ", isDestReachable(graph, 'A', 'E')==true?"True":"False" ) ; printf("\n Is vertex E reachable from B? : %s\n ", isDestReachable(graph, 'B', 'E')==true?"True":"False" ) ; printf("\n Is vertex D reachable from A? : %s \n ", isDestReachable(graph, 'A', 'D')==true?"True":"False" ) ; printf("\n Is vertex E reachable from D? : %s \n ", isDestReachable(graph, 'D', 'E')==true?"True":"False" ) ; printf("\n Is vertex B reachable from A? : %s \n ", isDestReachable(graph, 'A', 'B')==true?"True":"False" ) ; printf("\n Is vertex D reachable from C? : %s \n ", isDestReachable(graph, 'C', 'D')==true?"True":"False" ) ; return 0; }
bool CreateTestGraph1(Graph **graphOut){ GraphCreate(graphOut); if(GraphIsDestroyed(*graphOut)){ logError("fail - CreateTestGraph1() - GraphCreate() returned null."); return false; } size_t numNodes=5; /* Create node data */ char *nodesValues[numNodes]; for (int i=0; i<numNodes; i++){ nodesValues[i] = malloc(MAXDATALENGTH); snprintf(nodesValues[i],MAXDATALENGTH,"node %d",i); } /* Create connections with weights. 0 is unconnected. * 0 is connected to 1, 4 * 1 is connected to 0, 2, 3 * 2 is connected to 1, 3 * 3 is connected to 1 ,2 ,4 * 4 is connected to 0, 3 */ double adjMatrix [] ={ 0.0, 1.0, 0.0, 0.0, 4.0, 1.0, 0.0, 5.0, 1.0, 0.0, 0.0, 5.0, 0.0, 2.0, 0.0, 0.0, 1.0, 2.0, 0.0, 1.0, 4.0, 0.0, 0.0, 1.0, 0.0 }; if(!GraphInit(*graphOut,(void**) nodesValues, numNodes, adjMatrix)){ logError("fail - CreateTestGraph1() - GraphInit() was not successful."); return false; } /* char *expected = "Graph(5):\n" "Node(node 4): node 3, node 0\n" "Node(node 3): node 4, node 1, node 2\n" "Node(node 2): node 3, node 1\n" "Node(node 1): node 3, node 0, node 2\n" "Node(node 0): node 1, node 4\n"; const char *result = GraphToString(*graphOut); if(strncmp(expected,result,strlen(expected)) != 0){ logError("fail - GraphToString() did not return expected output: \nexpected:%s\nresult:%s\n",expected,result); return false; } free(result); logInfo(ListToString((*graphOut)->edges)); */ return true; }