diff --git a/thu_dsa/chp2/Fib.cpp b/thu_dsa/chp2/Fib.cpp index 096f719..73fa75a 100644 --- a/thu_dsa/chp2/Fib.cpp +++ b/thu_dsa/chp2/Fib.cpp @@ -1,16 +1,13 @@ -#include "Fib.h" -#include -using std::cout; -using std::endl; +#include "Vector.h" //constructor Fib::Fib(int n) { - elem = Vector(); + Vector(); int prev = 0, current = 1, tmp; - elem.push_back(prev); + push_back(prev); while (current < n) { - elem.push_back(current); + push_back(current); tmp = prev; prev = current; @@ -20,14 +17,14 @@ Fib::Fib(int n) { //external interfaces void Fib::print() { - for (int ix = 0; ix != elem.getSize(); ++ix) - cout << elem[ix] << endl; + for (int ix = 0; ix != getSize(); ++ix) + cout << operator[](ix) << endl; } int Fib::get() { - return elem[elem.getSize() - 1]; + return operator[](getSize() - 1); } void Fib::prev() { - elem.pop_back(); + pop_back(); } diff --git a/thu_dsa/chp2/Fib.h b/thu_dsa/chp2/Fib.h deleted file mode 100644 index ca3b372..0000000 --- a/thu_dsa/chp2/Fib.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef FIB_H_ -#define FIB_H_ - -#include "Vector.h" - -class Fib{ -protected: - Vector elem; -public: - //constructor - Fib(int n); - - void print(); - int get(); - void prev(); -}; - -#endif diff --git a/thu_dsa/chp2/Vector.h b/thu_dsa/chp2/Vector.h index d6e017f..00b4f88 100644 --- a/thu_dsa/chp2/Vector.h +++ b/thu_dsa/chp2/Vector.h @@ -1,7 +1,6 @@ #ifndef VECTOR_H_ #define VECTOR_H_ -#include "Fib.h" #include #define DEFAULT_CAPACITY 3 @@ -11,6 +10,10 @@ using std::cout; using std::endl; +template +class Vector; +class Fib; + template class Vector{ protected: @@ -322,4 +325,15 @@ void Vector::mergeSort(int lo, int hi){ merge(lo, mid, hi); } + +class Fib : public Vector { +public: + //constructor + Fib(int n); + + int get(); + void print(); + void prev(); +}; + #endif diff --git a/thu_dsa/chp2/testFib.cpp b/thu_dsa/chp2/testFib.cpp index 9491bdb..b1ad021 100644 --- a/thu_dsa/chp2/testFib.cpp +++ b/thu_dsa/chp2/testFib.cpp @@ -1,4 +1,4 @@ -#include "Fib.h" +#include "Vector.h" #include #include diff --git a/thu_dsa/chp2/testVector.cpp b/thu_dsa/chp2/testVector.cpp index fca246f..30d9e1d 100644 --- a/thu_dsa/chp2/testVector.cpp +++ b/thu_dsa/chp2/testVector.cpp @@ -1,4 +1,3 @@ -#include "Fib.h" #include "Vector.h" #include #include