I guess it doesn't protect the internal array, but my version of set is:
Code:
template<class Type>
void QueueType<Type>::addElement(Type newElement) {
if (isEmpty()) {
queueArray[0] = newElement;
front = back = 0;
numElements = 1;
} else {
back = (back + 1) % SIZE;
queueArray[back] = newElement;
numElements++;
}
}
(I'm implementing it as a circular array) It doesn't really do much aside from store values, reposition itsself (due to being circular) after item removal, and return the number of elements it has. My updateWaitTimes function in the template is:
Code:
template<class Type>
void QueueType<Type>::updateWaitTimes(Type*& element, int& position, int& counter) {
if (isEmpty()) {
element = NULL;
} else {
if (position == 0) {
position = front;
}
element = &queueArray[position];
position = (position + 1) % SIZE;
}
if (counter == numElements) {
element = NULL;
}
counter++;
}
(Type ends up being customerType and element is customerPointer) Where it actually takes 2 other int references to know when to stop and set the pointer to NULL, but all it really does is sets the pointer to the next element in its array.
Do you think it would be better to just add an iterator class along with begin/end/proper overloading functions needed so I can just use a range-based for loop in main? Instead of my weird pointer shenanigans.