Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions include/queue/queue.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,36 @@ void Queue<Data>::clear() {

template<class Data>
void Queue<Data>::push(Data data) {
if (size() >= QUEUE_SIZE - 1) {
throw std::overflow_error("Queue is full");
}
buffer[ep] = data;
ep = (ep + 1) % QUEUE_SIZE;
}

template<class Data>
Data Queue<Data>::pull() {
return buffer[sp];
if (size() == 0) {
throw std::underflow_error("Queue is empty");
}
Data data = buffer[sp];
sp = (sp + 1) % QUEUE_SIZE;
return data;
}

template<class Data>
Data Queue<Data>::top() {
if (size() == 0) {
throw std::underflow_error("Queue is empty (top)");
}
return buffer[sp];
}

template<class Data>
int Queue<Data>::size() {
return 0;
if (ep >= sp) {
return ep - sp;
} else {
return QUEUE_SIZE - sp + ep;
}
}