Skip to content

Commit

Permalink
add task3
Browse files Browse the repository at this point in the history
  • Loading branch information
Григорий Севергин committed Nov 13, 2024
1 parent bb1f313 commit c154de8
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,26 @@ jobs:
- name: Run tests
run: cd task2/build && ctest

task3:
runs-on: ubuntu-22.04
container:
image: lifestyle288/urfucpp:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
options: --name main-container
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install dependecies
run: |
cd task3
cp -R /app/tests/task3 tests
mkdir build
cd build
cmake ..
make -j4
- name: Run tests
run: cd task3/build && ctest
17 changes: 17 additions & 0 deletions task3/CMakeLists.txt
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)
21 changes: 21 additions & 0 deletions task3/README.md
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; // проверить заполнена ли очередь
};
```
36 changes: 36 additions & 0 deletions task3/circular_queue.cpp
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
}
14 changes: 14 additions & 0 deletions task3/circular_queue.hpp
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; // проверить заполнена ли очередь
};

0 comments on commit c154de8

Please sign in to comment.