void Graph::Build() { if(!adj_list_) adj_list_ = new Vertex(0); for(int i=1; i<6; i++) { Vertex *temp = new Vertex(i); AddVertex(temp); } Vertex *cur = VertexList(0); cur->AddEdge(VertexList(1)); cur->AddEdge(VertexList(2)); cur = VertexList(1); cur->AddEdge(VertexList(0)); cur = VertexList(2); cur->AddEdge(VertexList(0)); cur->AddEdge(VertexList(3)); cur->AddEdge(VertexList(4)); cur = VertexList(3); cur->AddEdge(VertexList(2)); cur->AddEdge(VertexList(4)); cur->AddEdge(VertexList(5)); cur = VertexList(4); cur->AddEdge(VertexList(2)); cur->AddEdge(VertexList(3)); cur->AddEdge(VertexList(5)); cur = VertexList(5); cur->AddEdge(VertexList(3)); cur->AddEdge(VertexList(4)); }
void DFS(Vertex * vertex) { Vertex * V = vertex; Edge * E = V->head; int ecnt = 0; V->visit = Visited; if (V == start && moveflag == 1) return; if (V == start && moveflag == 0) moveflag = 1; if (V == end) { flag = 1; total_weight += minimum; return; } while (E != NULL) { if (E->edgeflag == 0 && E->Target->visit == NonVisited && E->Target != NULL && flag == 0) { if (minimum > E->weight) minimum = E->weight; DFS(E->Target); } if (flag == 1) { Vertex * from = E->Target; Vertex * target = E->From; if (E->weight - minimum > 0) E->weight -= minimum; else V->DeleteEdge(ecnt); from->AddEdge(new Edge(from, target, minimum)); return; } E = E->Next; ecnt++; } }