2024-03-10 13:24:50 +00:00
|
|
|
#include "queue.h"
|
2024-03-09 15:44:29 +00:00
|
|
|
#include "sequence.h"
|
|
|
|
|
|
|
|
namespace seq
|
|
|
|
{
|
2024-03-10 13:24:50 +00:00
|
|
|
class DynamicArray: public Queue
|
2024-03-09 15:44:29 +00:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
|
2024-03-10 13:24:50 +00:00
|
|
|
void enqueue(int element);
|
|
|
|
int dequeue();
|
2024-03-09 15:44:29 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
}
|