Created
July 24, 2015 19:48
-
-
Save Jxrgxn/744b1edeb6d5400aad89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Lucas Larson | |
//7/19/15 | |
//problem 1 | |
//assignment #2 | |
#ifndef _ARRAY_BAG | |
#define _ARRAY_BAG | |
#include "BagInterface.h" | |
#include <vector> | |
#include <cstddef> | |
#include <string> | |
template<class ItemType> | |
class ArrayBag : public BagInterface<ItemType> | |
{ | |
private: | |
static const int DEFAULT_CAPACITY = 24; // the bag size a bit bigger to allow | |
// adding bags. | |
ItemType items[DEFAULT_CAPACITY]; // Array of bag items | |
int itemCount; // Current count of bag items | |
int maxItems; // Max capacity of the bag | |
// Returns either the index of the element in the array items that | |
// contains the given target or -1, if the array does not contain | |
// the target. | |
int getIndexOf(const ItemType& target) const; | |
int& operator[](size_t x) const { return items[x];}; | |
public: | |
ArrayBag(); | |
int getCurrentSize() const; | |
bool isEmpty() const; | |
bool add(const ItemType& newEntry); | |
void clear(); | |
bool remove(const ItemType& anEntry); | |
bool contains(const ItemType& target) const; | |
int getFrequencyOf(const ItemType& anEntry) const; | |
int merge(ArrayBag<string> a, ArrayBag<string> b); | |
std::vector<ItemType> toVector() const; | |
}; // end ArrayBag | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
template
int ArrayBag::merge(ArrayBag a, ArrayBag b) {
int newsz = a.getCurrentSize() + b.getCurrentSize();
if (newsz > a.DEFAULT_CAPACITY)
}