Add a constructor to Vector.h. Test class GraphMatrix, all tests passed. Dfs and Bfs remained to be done.

This commit is contained in:
Shine wOng
2019-06-03 21:40:02 +08:00
parent b638fbc71f
commit 3880e2125a
7 changed files with 233 additions and 27 deletions

View File

@@ -34,6 +34,7 @@ public:
//constructors
Vector();
Vector(int capacity);
Vector(int size, T const &value);
Vector(T* const A, int n) { copyfrom(A, 0, n); }
Vector(T* const A, int lo, int hi) { copyfrom(A, lo, hi); }
Vector(Vector<T> const &V) { copyfrom(V._elem, 0, V._size); }
@@ -149,6 +150,15 @@ Vector<T>::Vector(int capacity) {
_elem = new T[_capacity];
}
template<typename T>
Vector<T>::Vector(int size, T const &value){
_capacity = size << 1;
_size = size;
_elem = new T[_capacity];
for (int ix = 0; ix != _size; ++ix)
_elem[ix] = value;
}
//read-only interfaces
template<typename T>
void Vector<T>::print() {