-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Григорий Севергин
committed
Nov 13, 2024
1 parent
bb1f313
commit c154de8
Showing
5 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
cmake_minimum_required(VERSION 3.25) | ||
|
||
project(circular_queue) | ||
|
||
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror") | ||
|
||
find_package(Boost COMPONENTS unit_test_framework REQUIRED) | ||
if (Boost_FOUND) | ||
include_directories(${Boost_INCLUDE_DIRS}) | ||
endif (Boost_FOUND) | ||
|
||
add_library(circular_queue STATIC circular_queue.cpp) | ||
|
||
if (Boost_FOUND) | ||
enable_testing() | ||
add_subdirectory(tests) | ||
endif (Boost_FOUND) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Кольцевая очередь | ||
|
||
Кольцевая очередь (Circular Queue) — это структура данных, которая представляет собой очередь (FIFO) фиксированного размера. Кольцевая очередь использует буфер фиксированного размера таким образом, как будто бы после последнего элемента сразу же снова идет первый. Подробнее можно прочитать [здесь](https://www.programiz.com/dsa/circular-queue). | ||
|
||
Такая структура много где используется, например для организации различных очередей сообщений. | ||
|
||
#### Требуется реализовать интерфейс: | ||
|
||
```c++ | ||
class CircularQueue | ||
{ | ||
public: | ||
CircularQueue(size_t size); // создать очередь с определенным размером буффера | ||
bool Push(int value); // добавить значение в конец очереди (false, если очередь заполнена) | ||
bool Pop(); // удалить значение из начала очереди (false, если очередь пустая) | ||
int Front() const; // получить значение из начала очереди (-1, если очередь пустая) | ||
int Back() const; // получить значение из конца очереди (-1, если очередь пустая) | ||
bool Empty() const; // проверить пустая ли очередь | ||
bool Full() const; // проверить заполнена ли очередь | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "circular_queue.hpp" | ||
|
||
CircularQueue::CircularQueue(size_t size) | ||
{ | ||
// your implementation here | ||
} | ||
|
||
bool CircularQueue::Push(int value) | ||
{ | ||
// your implementation here | ||
} | ||
|
||
bool CircularQueue::Pop() | ||
{ | ||
// your implementation here | ||
} | ||
|
||
int CircularQueue::Front() const | ||
{ | ||
// your implementation here | ||
} | ||
|
||
int CircularQueue::Back() const | ||
{ | ||
// your implementation here | ||
} | ||
|
||
bool CircularQueue::Empty() const | ||
{ | ||
// your implementation here | ||
} | ||
|
||
bool CircularQueue::Full() const | ||
{ | ||
// your implementation here | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <cstddef> | ||
|
||
class CircularQueue { | ||
public: | ||
CircularQueue(size_t size); // создать очередь с определенным размером буффера | ||
bool Push(int value); // добавить значение в конец очереди (false, если очередь заполнена) | ||
bool Pop(); // удалить значение из начала очереди (false, если очередь пустая) | ||
int Front() const; // получить значение из начала очереди (-1, если очередь пустая) | ||
int Back() const; // получить значение из конца очереди (-1, если очередь пустая) | ||
bool Empty() const; // проверить пустая ли очередь | ||
bool Full() const; // проверить заполнена ли очередь | ||
}; |