28 lines
876 B
C++
28 lines
876 B
C++
#include "queue.h"
|
|
|
|
namespace seq
|
|
{
|
|
class DynamicArray: public Queue
|
|
{
|
|
public:
|
|
bool empty() const { return (this->logical_size == 0); } // test whether the array is empty
|
|
size_t size() const { return this->logical_size; } // return the logical size (number of items in the array)
|
|
|
|
void enqueue(int element);
|
|
int dequeue();
|
|
|
|
void clear(); // remove all the items from the array
|
|
~DynamicArray() { this->clear(); }
|
|
|
|
private:
|
|
// this is a static C/C++ array containing the actual data
|
|
// it is owned by the dynamic array
|
|
int* values = nullptr;
|
|
|
|
size_t logical_size = 0; // how many data items are we actually storing?
|
|
size_t capacity = 0; // how much memory did we allocate?
|
|
|
|
void resize(size_t new_capacity); // shift to static array with increased/decreased capacity
|
|
};
|
|
}
|