Skip to content

hw_algorithms#16

Open
not-phoenix-w wants to merge 11 commits intoDafeCpp:mainfrom
not-phoenix-w:main
Open

hw_algorithms#16
not-phoenix-w wants to merge 11 commits intoDafeCpp:mainfrom
not-phoenix-w:main

Conversation

@not-phoenix-w
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 15 out of 17. Check the log or trigger a new build to see more.

Comment thread task_01/src/main.cpp Outdated
Comment thread task_03/src/main.cpp Outdated
Comment thread task_03/src/main.cpp Outdated
#include <stack>
using namespace std;

vector<int> dailyTemp(const vecror<inr>& temp){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no template named 'vecror'; did you mean 'vector'? [clang-diagnostic-error]

Suggested change
vector<int> dailyTemp(const vecror<inr>& temp){
vector<int> dailyTemp(const vector<inr>& temp){
Additional context

/usr/include/c++/13/bits/stl_vector.h:427: 'vector' declared here

    class vector : protected _Vector_base<_Tp, _Alloc>
          ^

Comment thread task_03/src/main.cpp Outdated
#include <stack>
using namespace std;

vector<int> dailyTemp(const vecror<inr>& temp){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'inr'; did you mean 'int'? [clang-diagnostic-error]

Suggested change
vector<int> dailyTemp(const vecror<inr>& temp){
vector<int> dailyTemp(const vecror<int>& temp){

Comment thread task_04/src/main.cpp Outdated
Comment thread task_06/src/main.cpp Outdated
#include <iostream>

int findOrderStat(int[] arr, int k) {
int l= 0, r = arr.length;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'arr' [clang-diagnostic-error]

  int l= 0, r = arr.length;
                ^

Comment thread task_06/src/main.cpp Outdated
int findOrderStat(int[] arr, int k) {
int l= 0, r = arr.length;
while (true) {
int m = partition(arr, l, r);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'arr' [clang-diagnostic-error]

    int m = partition(arr, l, r);
                      ^

Comment thread task_06/src/main.cpp Outdated
while (true) {
int m = partition(arr, l, r);

if (m == k) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'k' [clang-diagnostic-error]

    if (m == k) {
             ^

Comment thread task_06/src/main.cpp Outdated
int m = partition(arr, l, r);

if (m == k) {
return arr[m];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'arr' [clang-diagnostic-error]

      return arr[m];
             ^

Comment thread task_06/src/main.cpp Outdated
if (m == k) {
return arr[m];
}
else if (k < m) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use of undeclared identifier 'k' [clang-diagnostic-error]

    else if (k < m) {
             ^

not-phoenix-w and others added 2 commits May 30, 2025 20:00
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Node *parent;

Node(int key, string colour, Node *left_child, Node *right_child, Node *parent = nullptr)
: key(key), colour(colour), left_child(left_child), right_child(right_child), parent(parent) {}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter 'colour' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param]

task_07/src/red_black_tree.hpp:2:

- #include <vector>
+ #include <utility>
+ #include <vector>
Suggested change
: key(key), colour(colour), left_child(left_child), right_child(right_child), parent(parent) {}
: key(key), colour(std::move(colour)), left_child(left_child), right_child(right_child), parent(parent) {}

private:
struct Node
{
bool full;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use default member initializer for 'full' [cppcoreguidelines-use-default-member-init]

Suggested change
bool full;
bool full{true};

task_08/src/hash_table.hpp:14:

-         Node(T value) : full(true), value(value) {}
+         Node(T value) : , value(value) {}

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread task_03/src/main.cpp Outdated
#include <stack>
using namespace std;

static vector<int> dailyTemp(const vecror<inr>& temp){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'dailyTemp' declared 'static', move to anonymous namespace instead [misc-use-anonymous-namespace]

static vector<int> dailyTemp(const vecror<inr>& temp){
                   ^

Comment thread task_03/src/main.cpp Outdated
#include <stack>
using namespace std;

static vector<int> dailyTemp(const vecror<inr>& temp){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no template named 'vecror'; did you mean 'vector'? [clang-diagnostic-error]

Suggested change
static vector<int> dailyTemp(const vecror<inr>& temp){
static vector<int> dailyTemp(const vector<inr>& temp){
Additional context

/usr/include/c++/13/bits/stl_vector.h:427: 'vector' declared here

    class vector : protected _Vector_base<_Tp, _Alloc>
          ^

Comment thread task_03/src/main.cpp Outdated
not-phoenix-w and others added 2 commits May 30, 2025 20:04
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread task_04/src/main.cpp

using namespace std;

static vector<pair<int, int>> bFish(const vector<int>& prices, int k){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'bFish' declared 'static', move to anonymous namespace instead [misc-use-anonymous-namespace]

static vector<pair<int, int>> bFish(const vector<int>& prices, int k){
                              ^

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread task_03/src/main.cpp Outdated
#include <stack>
using namespace std;

static vector<int> dailyTemp(const vecror<int>& temp){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'dailyTemp' declared 'static', move to anonymous namespace instead [misc-use-anonymous-namespace]

static vector<int> dailyTemp(const vecror<int>& temp){
                   ^

Comment thread task_03/src/main.cpp Outdated
#include <stack>
using namespace std;

static vector<int> dailyTemp(const vecror<int>& temp){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no template named 'vecror'; did you mean 'vector'? [clang-diagnostic-error]

Suggested change
static vector<int> dailyTemp(const vecror<int>& temp){
static vector<int> dailyTemp(const vector<int>& temp){
Additional context

/usr/include/c++/13/bits/stl_vector.h:427: 'vector' declared here

    class vector : protected _Vector_base<_Tp, _Alloc>
          ^

Comment thread task_01/src/main.cpp
Comment thread task_01/src/main.cpp Outdated
}
int left = 0;
int right = n-1;
while(left!=right)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если не найдётся пара чисел, сумма которых равна c, программа зациклится (while(left!=right)), т.к. выход только через break. Это может привести к бесконечному циклу.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправлено!

Comment thread task_01/src/main.cpp Outdated
int right = n-1;
while(left!=right)
{
if (a[left]+a[right]<c) {left+=1; continue;}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++left;
--right;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправлено!

Comment thread task_03/src/main.cpp Outdated
#include <stack>
using namespace std;

static vector<int> dailyTemp(const vecror<int>& temp){
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DailyTemp
и вынести в отдельный файл

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправлено!

Comment thread task_02/src/main.cpp
@@ -1,3 +1,6 @@
#include <iostream>
#include <vector>
using namespace std;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

второй задачи нет(

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я не до конца поняла, нужно было её делать или нет, т.к. в исходном файле уже было решение этой задачи

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

там реализация наивная и не оптимальная) нужно написать заново не на stack'е

Comment thread task_05/src/main.cpp Outdated

int main() { return 0; }
template <typename type_ar>
int part(type_ar *ar, int l, int r) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partition

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сделано!

Comment thread task_05/src/main.cpp Outdated
}

template <typename type_arrr>
void q_sort(type_arrr *arrr, int l, int r) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QuickSort

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправлено!

Comment thread task_06/src/main.cpp Outdated
@@ -1,3 +1,20 @@
#include <iostream>

int findOrderStat(int[] arr, int k) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FindOrderStat

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправлено!

Comment thread task_07/src/red_black_tree.hpp Outdated
private:
struct Node {
int key;
string colour;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше использовать enum

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправлено!

Comment thread task_07/src/red_black_tree.hpp Outdated

public:
Black_Red_Tree() {
nil = new Node(0, "BLACK", nullptr, nullptr);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

раз есть new значит должен быть и деструктор с delete

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправлено!

Comment thread task_07/src/red_black_tree.hpp Outdated
root = nil;
}

void insert(int key);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insert
Delete
and etc.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправлено!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Везде, где используется buffer[begin]->value, нет проверки, что buffer[begin] != nullptr. Это приведёт к разыменованию nullptr.

Copy link
Copy Markdown
Author

@not-phoenix-w not-phoenix-w Jun 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Увидела ошибку. Спасибо!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправлено!

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 15 out of 23. Check the log or trigger a new build to see more.

Comment thread task_01/src/main.cpp
Comment thread task_05/src/test.cpp

TEST(QuickSortTest, EmptyArray) {
int arr[] = {};
ASSERT_NO_THROW(QuickSort(arr, 0, -1));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

    int arr[] = {};
    ^

Comment thread task_05/src/test.cpp
TEST(QuickSortTest, EmptyArray) {
int arr[] = {};
ASSERT_NO_THROW(QuickSort(arr, 0, -1));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

    ASSERT_NO_THROW(QuickSort(arr, 0, -1));
                              ^

Comment thread task_05/src/test.cpp

TEST(QuickSortTest, SingleElement) {
int arr[] = {42};
TestSorting(arr, 1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

    int arr[] = {42};
    ^

Comment thread task_05/src/test.cpp
TEST(QuickSortTest, SingleElement) {
int arr[] = {42};
TestSorting(arr, 1);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

    TestSorting(arr, 1);
                ^

Comment thread task_05/src/test.cpp

TEST(QuickSortTest, DuplicateElements) {
int arr[] = {2, 2, 1, 1, 3, 3};
TestSorting(arr, 6);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

    int arr[] = {2, 2, 1, 1, 3, 3};
    ^

Comment thread task_05/src/test.cpp
TEST(QuickSortTest, DuplicateElements) {
int arr[] = {2, 2, 1, 1, 3, 3};
TestSorting(arr, 6);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

    TestSorting(arr, 6);
                ^

Comment thread task_05/src/test.cpp

TEST(QuickSortTest, FloatArray) {
float arr[] = {1.5f, 0.5f, 2.5f, 1.1f, 3.3f};
TestSorting(arr, 5);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

    float arr[] = {1.5f, 0.5f, 2.5f, 1.1f, 3.3f};
    ^

Comment thread task_05/src/test.cpp
TEST(QuickSortTest, FloatArray) {
float arr[] = {1.5f, 0.5f, 2.5f, 1.1f, 3.3f};
TestSorting(arr, 5);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

    TestSorting(arr, 5);
                ^


// Случай 1: У z нет левого потомка
if (z->left_child == nil) {
x = z->right_child;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: Use of memory after it is freed [clang-analyzer-cplusplus.NewDelete]

olour = Colour::Black;
      ^
Additional context

task_07/src/red_black_tree.cpp:251: Calling 'RedBlackTree::Search'

 Search(key);
 ^

task_07/src/red_black_tree.cpp:117: Assuming 'current' is not equal to field 'nil'

* current = root;
                             ^

task_07/src/red_black_tree.cpp:117: Left side of '&&' is true

* current = root;
                             ^

task_07/src/red_black_tree.cpp:117: Assuming 'key' is equal to field 'key'

* current = root;
                                               ^

task_07/src/red_black_tree.cpp:117: Loop condition is false. Execution continues on line 125

* current = root;
                      ^

task_07/src/red_black_tree.cpp:251: Returning from 'RedBlackTree::Search'

 Search(key);
 ^

task_07/src/red_black_tree.cpp:251: 'z' is not equal to field 'nil'

 Search(key);
                      ^

task_07/src/red_black_tree.cpp:251: Taking false branch

 Search(key);
                  ^

task_07/src/red_black_tree.cpp:256: Assuming field 'left_child' is not equal to field 'nil'

евого потомка
                                  ^

task_07/src/red_black_tree.cpp:256: Taking false branch

евого потомка
                              ^

task_07/src/red_black_tree.cpp:264: Assuming field 'right_child' is equal to field 'nil'

(z->right_child == nil) {
 ^

task_07/src/red_black_tree.cpp:263: Taking true branch

потомка
                        ^

task_07/src/red_black_tree.cpp:266: Calling 'RedBlackTree::Transplant'

 Transplant(z, z->left_child);
 ^

task_07/src/red_black_tree.cpp:165: Assuming field 'parent' is not equal to field 'nil'

 (u->parent == nil) {
  ^

task_07/src/red_black_tree.cpp:164: Taking false branch

ansplant(Node* u, Node* v) {
                                 ^

task_07/src/red_black_tree.cpp:168: Assuming 'u' is not equal to field 'left_child'

u == u->parent->left_child) {
^

task_07/src/red_black_tree.cpp:167: Taking false branch

e if (u == u->parent->left_child) {
  ^

task_07/src/red_black_tree.cpp:266: Returning from 'RedBlackTree::Transplant'

 Transplant(z, z->left_child);
 ^

task_07/src/red_black_tree.cpp:-1: Memory is released

child);
                                                                                                                                                                                                                                                      ^

task_07/src/red_black_tree.cpp:-1: Assuming 'yOriginalColor' is equal to Black

child);
                                                                                                                                                                                                                                                                         ^

task_07/src/red_black_tree.cpp:-1: Taking true branch

child);
                                                                                                                                                                                                                                                                     ^

task_07/src/red_black_tree.cpp:-1: Calling 'RedBlackTree::FixDel'

child);
                                                                                                                                                                                                                                                                                                                    ^

task_07/src/red_black_tree.cpp:181: Assuming 'x' is not equal to field 'root'

Tree::FixDel(Node* x) {
                                   ^

task_07/src/red_black_tree.cpp:181: Left side of '&&' is true

Tree::FixDel(Node* x) {
                                   ^

task_07/src/red_black_tree.cpp:182: Assuming field 'colour' is equal to Black

& x->colour == Colour::Black) {
  ^

task_07/src/red_black_tree.cpp:181: Loop condition is true. Entering loop body

Tree::FixDel(Node* x) {
                            ^

task_07/src/red_black_tree.cpp:183: Assuming 'x' is equal to field 'left_child'

if (x == x->parent->left_child) {
    ^

task_07/src/red_black_tree.cpp:183: Taking true branch

if (x == x->parent->left_child) {
^

task_07/src/red_black_tree.cpp:186: Field 'colour' is not equal to Red

                    ^

task_07/src/red_black_tree.cpp:186: Taking false branch

             ^

task_07/src/red_black_tree.cpp:193: Assuming field 'colour' is not equal to Black

   if (w->left_child->colour == Colour::Black && w->right_child->colour == Colour::Black) {
       ^

task_07/src/red_black_tree.cpp:194: Left side of '&&' is false

>colour == Colour::Black && w->right_child->colour == Colour::Black) {
                         ^

task_07/src/red_black_tree.cpp:199: Assuming field 'colour' is not equal to Black

       if (w->right_child->colour == Colour::Black) {
           ^

task_07/src/red_black_tree.cpp:199: Taking false branch

       if (w->right_child->colour == Colour::Black) {
       ^

task_07/src/red_black_tree.cpp:181: 'x' is equal to field 'root'

Tree::FixDel(Node* x) {
                                   ^

task_07/src/red_black_tree.cpp:181: Left side of '&&' is false

Tree::FixDel(Node* x) {
                                             ^

task_07/src/red_black_tree.cpp:248: Use of memory after it is freed

olour = Colour::Black;
      ^

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@@ -0,0 +1,65 @@
#pragma once
enum class Colour{ Red = 0, Black };
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: enum 'Colour' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]

enum class Colour{ Red = 0, Black };
           ^


public:
RedBlackTree() {
nil = new Node(0, Colour::Black, nullptr, nullptr);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'nil' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]

task_07/src/red_black_tree.hpp:41:

-     RedBlackTree() {
-         nil = new Node(0, Colour::Black, nullptr, nullptr);
+     RedBlackTree() : nil(new Node(0, Colour::Black, nullptr, nullptr)) {
+         

Comment thread task_07/src/test.cpp

class RedBlackTreeTest : public ::testing::Test {
protected:
RedBlackTree tree;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'tree' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

    RedBlackTree tree;
                 ^

Comment thread task_08/src/test.cpp
#include <gtest/gtest.h>
#include "hash_table.hpp"

size_t simple_begin_hash(int value) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'simple_begin_hash' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]

Suggested change
size_t simple_begin_hash(int value) {
static size_t simple_begin_hash(int value) {

Comment thread task_08/src/test.cpp
TEST(TopologySort, Simple) {
ASSERT_EQ(1, 1); // Stack []
size_t simple_step_hash(int value) {
return value + 1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'simple_step_hash' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]

Suggested change
size_t simple_step_hash(int value) {
static size_t simple_step_hash(int value) {

Comment thread task_08/src/test.cpp
}

class HashTableTest : public ::testing::Test {
protected:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: constructor does not initialize these fields: table [cppcoreguidelines-pro-type-member-init]

task_08/src/test.cpp:21:

-     Hashtable<int>* table;
+     Hashtable<int>* table{};

Comment thread task_08/src/test.cpp
}

Hashtable<int>* table;
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'table' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

    Hashtable<int>* table;
                    ^

Comment thread doc/topic2/FenwickTree.md
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

удали из домашки плиз теорию

Comment thread task_01/src/solution.hpp
#include <vector>
using namespace std;

struct Result
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

норм решение, но лучше обернуть все в std::optional, станет красивее

Comment thread task_01/src/solution.hpp
int left = 0, right = 0;
};

inline Result Solve(int n, int c, const vector<int>& a)
Copy link
Copy Markdown
Contributor

@LostPointer LostPointer Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай не a а array и другие имена тоже

n тут не нужна) просто сделай array.size()

Copy link
Copy Markdown
Contributor

@LostPointer LostPointer Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::optional<Result> SumOfTwo(int sum_of_two, const vector<int>& array) будет выглдеть намного лучше)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

и лучше сделай еще один файл cpp и туда реализацию перекинь) и имя файлу лучше придумать по лучше

Comment thread task_04/src/solution.hpp

using namespace std;

inline vector<pair<int, int>> BFish(const vector<int>& prices, int k) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а зачем везде inline использовать для функций?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

и тут лучше как в первой задаче сделать структуру, а не пару

Comment thread task_05/src/solution.hpp
#include <cmath>
using namespace std;

template <typename type_ar>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай не type_ar а ArrayType или что то подобное, будет красивее, а когда красивее я довольнее и значит оценка выше)

@DafeCpp DafeCpp deleted a comment from github-actions Bot Jun 23, 2025
Comment thread task_05/src/solution.hpp
}

template <typename type_arrr>
void QuickSort(type_arrr *arrr, int l, int r) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не очень хорошие названия параметров, непонятно что они означают

Copy link
Copy Markdown
Contributor

@LostPointer LostPointer Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ну и если хочешь ещё улучшить то лучше не передавать указатель на массив, а считать что это контейнер с произвольным доступом)

в идеале вот так:

template <typename Container>
concept SortableContainer = requires(Container a, int i, int j) {
    { a[i] } -> std::convertible_to<typename Container::value_type>;
    { a.size() } -> std::convertible_to<std::size_t>;
    { a[i] < a[j] } -> std::convertible_to<bool>;
    { a[i] > a[j] } -> std::convertible_to<bool>;
    { swap(a[i], a[j]) };
};

template <SortableContainer Container>
void QuickSort(Container& array)

Comment thread task_06/src/solution.hpp

using namespace std;

inline int Partition(vector<int> ar, int l, int r) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

довольно странно что тесты проходят, ты тут swap(ar[i++], ar[j--]); делаешь, и меняешь порядок элементов, но в копии ar тут похоже нужно передавать по ссылке а не по значению, это ускорит и будет правильнее работать

Comment thread task_06/src/solution.hpp
throw out_of_range("Invalid k value or empty array");
}

int l = 0, r = arr.size();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай 1 строка одно объявление

и тут у тебя r = size() и в Partition будешь вылезать на 1 элемент из вектора, нужно size() - 1

Node *y = nil;
Node *x = root;

while (x != nil) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil? может nullptr?

};

Node *root;
Node *nil;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

довольно странное решение, лучше использовать nullptr

@@ -0,0 +1,65 @@
#pragma once
enum class Colour{ Red = 0, Black };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно перенести внутрь Node, что бы не светить наружу реализацию

@DafeCpp DafeCpp deleted a comment from github-actions Bot Jun 23, 2025
std::function<size_t(T)> beginHash, stepHash;

public:
Hashtable(std::function<size_t(T)> beginHash, std::function<size_t(T)> stepHash) : beginHash(beginHash), stepHash(stepHash) {};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

хорошо бы и деструктор завести, раз выделяем память через new в векторе, а то будет утечка

Comment thread task_08/src/main.cpp
#include <iostream>

int main() { return 0; }
using namespace std;
Copy link
Copy Markdown
Contributor

@LostPointer LostPointer Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай удалим раз уж закоментировали)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants