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:
Shine wOng
2019-05-25 18:14:14 +08:00
parent fcdc3a4ec3
commit c13e3acaee
5 changed files with 24 additions and 32 deletions

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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

View File

@@ -1,4 +1,4 @@
#include "Fib.h"
#include "Vector.h"
#include <cassert>
#include <iostream>

View File

@@ -1,4 +1,3 @@
#include "Fib.h"
#include "Vector.h"
#include <time.h>
#include <cassert>