Skip to content

Commit

Permalink
Лазуткин М.К. 3
Browse files Browse the repository at this point in the history
  • Loading branch information
ADOBbIU authored Nov 20, 2024
1 parent 5297926 commit 541e70c
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions task3/circular_queue.cpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
#include "circular_queue.hpp"
#include <stdexcept>

CircularQueue::CircularQueue(size_t size)
{
// your implementation here
}
: buffer(size), head(0), tail(0), capacity(size), size(0) {}

bool CircularQueue::Push(int value)
{
// your implementation here
bool CircularQueue::Push(int value) {
if (Full()) {
return false;
}
buffer[tail] = value;
tail = (tail + 1) % capacity;
size++;
return true;
}

bool CircularQueue::Pop()
{
// your implementation here
bool CircularQueue::Pop() {
if (Empty()) {
return false;
}
head = (head + 1) % capacity;
size--;
return true;
}

int CircularQueue::Front() const
{
// your implementation here
int CircularQueue::Front() const {
if (Empty()) {
return -1;
}
return buffer[head];
}

int CircularQueue::Back() const
{
// your implementation here
int CircularQueue::Back() const {
if (Empty()) {
return -1;
}
return buffer[(tail + capacity - 1) % capacity];
}

bool CircularQueue::Empty() const
{
// your implementation here
bool CircularQueue::Empty() const {
return size == 0;
}

bool CircularQueue::Full() const
{
// your implementation here
bool CircularQueue::Full() const {
return size == capacity;
}

0 comments on commit 541e70c

Please sign in to comment.