-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayBag.h
45 lines (37 loc) · 1.29 KB
/
ArrayBag.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once
// Created by Frank M. Carrano and Tim Henry.
// Copyright (c) 2016 __Pearson Education__. All rights reserved.
//Modified by TAA to remove templates and Inheritance
/** ADT bag: Array-based implementation.
@file ArrayBag.h */
#ifndef BAG_
#define BAG_
#include <vector>
typedef int ItemType;
class ArrayBag
{
private:
static const int DEFAULT_BAG_SIZE = 100;
ItemType items[DEFAULT_BAG_SIZE]; // 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;
public:
ArrayBag();
int getCurrentSize() const;
bool isEmpty() const;
bool add(const ItemType& newEntry);
bool remove(const ItemType& anEntry);
void clear();
bool contains(const ItemType& anEntry) const;
int getFrequencyOf(const ItemType& anEntry) const;
std::vector<ItemType> toVector() const;
//overload operator for adding arraybags. removes any duplicate #s
ArrayBag operator + (const ArrayBag &);
//overload operator for subtracting arraybags
ArrayBag operator - (const ArrayBag &);
}; // end Bag
#endif