diff --git a/ex11/ex11.cpp b/ex11/ex11.cpp index 604567c..71e57d6 100644 --- a/ex11/ex11.cpp +++ b/ex11/ex11.cpp @@ -1,7 +1,8 @@ #include "graph.hpp" - +#include int main() { graphVertex gv; + printf("OK"); return 0; } \ No newline at end of file diff --git a/ex11/graph.hpp b/ex11/graph.hpp index 7f5a373..c3c1803 100644 --- a/ex11/graph.hpp +++ b/ex11/graph.hpp @@ -72,7 +72,7 @@ public: for (int j = 0; j < n; j++) delete V[j]; } - virtual Tv Vertex(int i) + virtual Tv vertex(int i) { return V[i]->data; } @@ -88,7 +88,8 @@ public: { if (V[id] == NULL) { - V[id] = new ::Vertex(value); + Vertex* temp= new Vertex(value); + V.put(id, temp); // E[id] = new Vector>; } else @@ -103,14 +104,14 @@ public: if (E[id][j] != NULL) { delete E[id][j]; - E[id][j] = NULL; + E[id].put(j,NULL); V[j]->inDegree--; } } v--; - Tv temp = Vertex(id); + Tv temp = vertex(id); delete V[id]; - V[id] = NULL; + V.put(id, NULL); } // id1->id2 进行连接 @@ -126,8 +127,8 @@ public: return -2; V[id1]->outDegree++; V[id2]->inDegree++; - - E[id1][id2] = new Edge(w); + Edge* temp=new Edge(w); + E[id1].put(id2, temp); return 0; } // 解除 id1->id2 连接 diff --git a/ex11/vector.hpp b/ex11/vector.hpp index acae663..cb138bd 100644 --- a/ex11/vector.hpp +++ b/ex11/vector.hpp @@ -6,7 +6,7 @@ template class Vector { -public: +private: T *_v; int _len; int _used; @@ -16,7 +16,7 @@ public: void shrink(); void adjust(); - +public: Vector(int len) { _used = 0; @@ -84,7 +84,7 @@ template void Vector::put(int a, T value) { - while (i >= _len) + while (a >= _len) { expand(); }