BAN: Implement back() for CircularQueue

This commit is contained in:
Bananymous 2024-06-11 00:05:11 +03:00
parent ffacff67cf
commit caa0111c79
1 changed files with 17 additions and 0 deletions

View File

@ -31,6 +31,9 @@ namespace BAN
const T& front() const;
T& front();
const T& back() const;
T& back();
size_type size() const { return m_size; }
bool empty() const { return size() == 0; }
bool full() const { return size() == capacity(); }
@ -98,6 +101,20 @@ namespace BAN
return *element_at(m_first);
}
template<typename T, size_t S>
const T& CircularQueue<T, S>::back() const
{
ASSERT(!empty());
return *element_at((m_first + m_size - 1) % capacity());
}
template<typename T, size_t S>
T& CircularQueue<T, S>::back()
{
ASSERT(!empty());
return *element_at((m_first + m_size - 1) % capacity());
}
template<typename T, size_t S>
const T* CircularQueue<T, S>::element_at(size_type index) const
{