Skip to content

tasks1-9#21

Open
PETROVGRIGORIY wants to merge 2 commits intoDafeCpp:mainfrom
PETROVGRIGORIY:homework
Open

tasks1-9#21
PETROVGRIGORIY wants to merge 2 commits intoDafeCpp:mainfrom
PETROVGRIGORIY:homework

Conversation

@PETROVGRIGORIY
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

Comment thread task_01/src/task1.cpp Outdated

#include <vector>

std::vector<int> FindNumberOfSumma(std::vector<int> vec, int summa); No newline at end of file
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 'FindNumberOfSumma' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]

Suggested change
std::vector<int> FindNumberOfSumma(std::vector<int> vec, int summa);
static std::vector<int> FindNumberOfSumma(std::vector<int> vec, int summa);

Comment thread task_01/src/task1.hpp
throw std::runtime_error("Vector is empty");
}
int start_iterator{0};
int end_iterator{vec.size() - 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: non-constant-expression cannot be narrowed from type 'size_type' (aka 'unsigned long') to 'int' in initializer list [clang-diagnostic-c++11-narrowing]

  int end_iterator{vec.size() - 1};
                   ^
Additional context

task_01/src/task1.hpp:8: insert an explicit cast to silence this issue

  int end_iterator{vec.size() - 1};
                   ^

std::vector<int> days_to_warming;
std::stack<std::pair<int, int>> decreasing_stack;

int last_index{temperature_list.size() - 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: non-constant-expression cannot be narrowed from type 'size_type' (aka 'unsigned long') to 'int' in initializer list [clang-diagnostic-c++11-narrowing]

  int last_index{temperature_list.size() - 1};
                 ^
Additional context

task_03/src/topology_sort.cpp:15: insert an explicit cast to silence this issue

  int last_index{temperature_list.size() - 1};
                 ^

Comment thread task_04/src/task4.hpp Outdated
#include <queue>
#include <utility>

std::vector<int> BuyFish(std::vector<int> price_list, int period) {
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 'BuyFish' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]

std::vector<int> BuyFish(std::vector<int> price_list, int period) {
                 ^
Additional context

task_04/src/task4.hpp:7: make as 'inline'

std::vector<int> BuyFish(std::vector<int> price_list, int period) {
                 ^

Comment thread task_06/src/task6.hpp
right_arr.push_back(vec[i]);
}
}
int pivot_index{left_arr.size()};
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: non-constant-expression cannot be narrowed from type 'size_type' (aka 'unsigned long') to 'int' in initializer list [clang-diagnostic-c++11-narrowing]

  int pivot_index{left_arr.size()};
                  ^
Additional context

task_06/src/task6.hpp:17: insert an explicit cast to silence this issue

  int pivot_index{left_arr.size()};
                  ^

Comment thread task_07/src/splay.hpp
q.push(root);
int level{0};
while (!q.empty()) {
Node<K, V> *current = q.front();
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 'x' is unused [misc-unused-parameters]

Suggested change
Node<K, V> *current = q.front();
> * /*x*/) {

Comment thread task_09/src/task9.hpp
#include <iostream>
#include <vector>

std::vector<int> PreprocessMaxReach(std::vector<std::vector<int>>& a) {
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 'PreprocessMaxReach' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]

std::vector<int> PreprocessMaxReach(std::vector<std::vector<int>>& a) {
                 ^
Additional context

task_09/src/task9.hpp:7: make as 'inline'

std::vector<int> PreprocessMaxReach(std::vector<std::vector<int>>& a) {
                 ^

Comment thread task_09/src/task9.hpp
return max_reach_for_row;
}

bool CheckRangeSorted(const std::vector<int>& max_reach_for_row, int l, int 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: function 'CheckRangeSorted' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]

bool CheckRangeSorted(const std::vector<int>& max_reach_for_row, int l, int r) {
     ^
Additional context

task_09/src/task9.hpp:42: make as 'inline'

bool CheckRangeSorted(const std::vector<int>& max_reach_for_row, int l, int r) {
     ^

Comment thread task_01/src/task1.cpp Outdated
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

Choose a reason for hiding this comment

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

и кажется тут перепутаны cpp и hpp

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.

У меня каждый раз падает сборка. Никак решить не могу проблему. я буду реалезацию в hpp писать, а cpp пустым оставлять

Comment thread task_01/src/task1.cpp Outdated
@@ -0,0 +1,5 @@
#pragma ones
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.

pragma once

Comment thread task_01/src/task1.hpp Outdated
}
int start_iterator{0};
int end_iterator{vec.size() - 1};
std::vector<int> return_vector;
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.

лучше и короче будет не return_vector а result

Comment thread task_01/src/task1.hpp Outdated
#include <vector>
#include <stdexcept>

std::vector<int> FindNumberOfSumma(std::vector<int> vec, int summa) {
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.

summa транслит в коде плохая практика

Comment thread task_02/src/stack.hpp Outdated
@@ -1,23 +1,72 @@
#pragma once
#ifndef STACK_H
#define STACK_H
Copy link
Copy Markdown
Contributor

@LostPointer LostPointer Jun 22, 2025

Choose a reason for hiding this comment

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

в прошлой задаче использовал #pragma once (хотя и не совсем правильно:)) тут через ifndef, выбери один вариант и используй его везде. я за #pragma, но ты можешь выбрать что тебе удобнее

Comment thread task_02/src/stack.hpp
private:
std::stack<int> data_;
void Pop() {
if (IsEmpty()) {
Copy link
Copy Markdown
Contributor

@LostPointer LostPointer Jun 22, 2025

Choose a reason for hiding this comment

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

класс не шаблонный, лучше перенести реализацию в cpp файл

и в других местах тоже

Comment thread task_02/src/stack.hpp Outdated
return minStack.back();
}

bool isEmpty() { return stack.empty(); }
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.

IsEmpty

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_03/src/topology_sort.cpp Outdated
temperature_list[i] >= decreasing_stack.top().first) {
decreasing_stack.pop();
}
if (decreasing_stack.size() == 0) {
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.

лучше decreasing_stack.empty()

Comment thread task_04/src/task4.cpp
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 и hpp

Comment thread task_05/src/heap.hpp Outdated
}

template <typename T>
std::vector<T> Heap_sort(std::vector<T> list) {
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.

HeapSort

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

throw std::runtime_error("Vector is empty");
}
int start_iterator{0};
int end_iterator{vec.size() - 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: non-constant-expression cannot be narrowed from type 'size_type' (aka 'unsigned long') to 'int' in initializer list [clang-diagnostic-c++11-narrowing]

  int end_iterator{vec.size() - 1};
                   ^
Additional context

task_01/src/find_numbers.cpp:7: insert an explicit cast to silence this issue

  int end_iterator{vec.size() - 1};
                   ^

std::vector<int> days_to_warming;
std::stack<std::pair<int, int>> decreasing_stack;

int last_index{temperature_list.size() - 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: non-constant-expression cannot be narrowed from type 'size_type' (aka 'unsigned long') to 'int' in initializer list [clang-diagnostic-c++11-narrowing]

  int last_index{temperature_list.size() - 1};
                 ^
Additional context

task_03/src/find_days_to_warm.cpp:15: insert an explicit cast to silence this issue

  int last_index{temperature_list.size() - 1};
                 ^

Comment thread task_07/src/splay.hpp

template <typename K, typename V>
Node<K, V> *SplayTree<K, V>::maximum() {
Node<K, V> *max = root;
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

Comment thread task_07/src/splay.hpp
}

template <typename K, typename V>
std::vector<K> SplayTree<K, V>::tree_vector(Node<K, V> *x) {
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.

x не используется в методе, ошибка?

Comment thread task_07/src/test.cpp
*/
}

int main(int argc, char **argv) {
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.

а это обязательно?

void Print() const;

private:
std::vector<std::vector<Node<K, V>>> hash_vector;
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::vector<std::list<..>> удаление будет проще

if (Contains(key)) {
std::vector<Node<K, V>> buf_vector;
for (auto node : hash_vector[index]) {
if (node.key != 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.

number_of_elemnts в этом методе не уменьшается

private:
std::vector<std::vector<Node<K, V>>> hash_vector;
void ReHashVector();
int number_of_elemnts{0};
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.

number_of_elements опечатка

Comment thread task_04/src/task4.hpp
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.

хорошо бы все файлы нормально называть)

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