Skip to content
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ include(cmake/function.cmake) # подхватываем функции,
# для простоты мы объединили наборы команд для создания статической библиотеки
# и для создания исполняемого проекта в отдельные функции

add_subdirectory(lib_easy_example) # подключаем дополнительный CMakeLists.txt из подкаталога с именем lib_easy_example
add_subdirectory(lib_easy_example)
add_subdirectory(lib_queue)
add_subdirectory(lib_stack)
add_subdirectory(lib_algorithms)
add_subdirectory(lib_list)
add_subdirectory(lib_doubly_linked_list)
add_subdirectory(lib_tvector) # подключаем дополнительный CMakeLists.txt из подкаталога с именем lib_easy_example

add_subdirectory(main) # подключаем дополнительный CMakeLists.txt из подкаталога с именем main

Expand Down
1 change: 1 addition & 0 deletions lib_DSU/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create_project_lib(DSU)
48 changes: 48 additions & 0 deletions lib_DSU/DSU.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "DSU.h"
#include <stdexcept>

DSU::DSU(int size):_size(size) {
_parent = new int[_size];
_rank = new int[_size];
for (int i = 0; i < _size; i++) {
_parent[i] = i;
_rank[i] = 0;
}
}

DSU::~DSU() {
delete[] _parent;
delete[] _rank;
}

int DSU::find(int x) {
if (_parent[x] != x) {
_parent[x] = find(_parent[x]);
}
return _parent[x];
}

void DSU::unionSets(int x, int y) {
if (x == y) {
return;
}
int rank_x = find(x);
int rank_y = find(y);
if (rank_x == rank_y) {
return;
}
if (_rank[rank_x] < _rank[rank_y]) {
_parent[rank_x] = rank_y;
}
else if (_rank[rank_x] > _rank[rank_y]) {
_parent[rank_y] = rank_x;
}
else {
_parent[rank_y] = rank_x;
_rank[rank_x]++;
}
}

int DSU::rank(int x) const {
return _rank[x];
}
22 changes: 22 additions & 0 deletions lib_DSU/DSU.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef dsuh
#define dsuh

class DSU {
private:
int* _parent;
int* _rank;
int _size;

public:
DSU(int size);

~DSU();

int find(int x);

void unionSets(int x, int y);

int rank(int x) const;
};

#endif
2 changes: 2 additions & 0 deletions lib_algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
create_project_lib(Algorithms)
add_depend(Algorithms Stack ..\\lib_stack)
36 changes: 36 additions & 0 deletions lib_algorithms/algorithms.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <stack>
#include "algorithms.h"
#include <string>

using std::string;

bool check_breckets(std::string str) {
std::stack<char> stack;

if (str.empty()) {
return true;
}

for (char c : str) {
if (c == '(' || c == '[' || c == '{') {
stack.push(c);
}
else if (c == ')' || c == ']' || c == '}') {
if (stack.empty()) {
return false;
}

if ((c == ')' && stack.top() != '(') ||
(c == ']' && stack.top() != '[') ||
(c == '}' && stack.top() != '{')) {
return false;
}
stack.pop();
}
else {
return false;
}
}

return stack.empty();
}
7 changes: 7 additions & 0 deletions lib_algorithms/algorithms.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef ALGORITHMS
#define ALGORITHMS
#include <string>

bool check_breckets(std::string);

#endif
1 change: 1 addition & 0 deletions lib_doubly_linked_list/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create_project_lib(Doubly_linked_list)
Empty file.
Empty file.
1 change: 1 addition & 0 deletions lib_list/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create_project_lib(List)
1 change: 1 addition & 0 deletions lib_list/list.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "list.h"
Loading