merge class Fib into the Vector.h file, delete the original Fib.h file, in order to obtain high usability.
This commit is contained in:
@@ -1,16 +1,13 @@
|
||||
#include "Fib.h"
|
||||
#include <iostream>
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
#include "Vector.h"
|
||||
|
||||
//constructor
|
||||
Fib::Fib(int n) {
|
||||
elem = Vector<int>();
|
||||
Vector<int>();
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#ifndef FIB_H_
|
||||
#define FIB_H_
|
||||
|
||||
#include "Vector.h"
|
||||
|
||||
class Fib{
|
||||
protected:
|
||||
Vector<int> elem;
|
||||
public:
|
||||
//constructor
|
||||
Fib(int n);
|
||||
|
||||
void print();
|
||||
int get();
|
||||
void prev();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef VECTOR_H_
|
||||
#define VECTOR_H_
|
||||
|
||||
#include "Fib.h"
|
||||
#include <iostream>
|
||||
|
||||
#define DEFAULT_CAPACITY 3
|
||||
@@ -11,6 +10,10 @@
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
template<typename T>
|
||||
class Vector;
|
||||
class Fib;
|
||||
|
||||
template<typename T>
|
||||
class Vector{
|
||||
protected:
|
||||
@@ -322,4 +325,15 @@ void Vector<T>::mergeSort(int lo, int hi){
|
||||
merge(lo, mid, hi);
|
||||
}
|
||||
|
||||
|
||||
class Fib : public Vector<int> {
|
||||
public:
|
||||
//constructor
|
||||
Fib(int n);
|
||||
|
||||
int get();
|
||||
void print();
|
||||
void prev();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "Fib.h"
|
||||
#include "Vector.h"
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "Fib.h"
|
||||
#include "Vector.h"
|
||||
#include <time.h>
|
||||
#include <cassert>
|
||||
|
||||
Reference in New Issue
Block a user