Skip to content

HOMEWORK 1#11

Open
Lynech wants to merge 5 commits intoAlgorithmsDafeMipt2024:mainfrom
Lynech:HOMEWORK_1
Open

HOMEWORK 1#11
Lynech wants to merge 5 commits intoAlgorithmsDafeMipt2024:mainfrom
Lynech:HOMEWORK_1

Conversation

@Lynech
Copy link
Copy Markdown

@Lynech Lynech commented Feb 23, 2024

attempt 1

attempt 1
Comment thread task_01/src/topology_sort.cpp Outdated
@@ -1 +1,16 @@
#include "topology_sort.hpp"

std::tuple<bool, int *, int *> topology_sort(int *arr, int n, int m) {
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.

имя функции не отображает что она делает, и не в том кодстайле (TopologySort)

Comment thread task_01/src/topology_sort.cpp Outdated
#include "topology_sort.hpp"

std::tuple<bool, int *, int *> topology_sort(int *arr, int n, int m) {
int *b = arr, *e = arr + (n - 1);
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.

b и e плохие названия переменных

Comment thread task_01/src/topology_sort.cpp Outdated

std::tuple<bool, int *, int *> topology_sort(int *arr, int n, int m) {
int *b = arr, *e = arr + (n - 1);
bool found = 1;
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 а true

Comment thread task_01/src/test.cpp
Comment thread task_01/src/topology_sort.cpp Outdated
#include "topology_sort.hpp"

std::tuple<bool, int *, int *> SummanddsInArray(int *arr, int n, int sum) {
int *begin = arr, *end = arr + (n - 1);
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/topology_sort.cpp Outdated
begin++;
if ((!begin) || (!end) || (begin >= end) || (*begin + *end != sum)) {
begin = end = nullptr;
found = 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.

found = true;

Comment thread task_01/src/topology_sort.cpp Outdated
@@ -1 +1,16 @@
#include "topology_sort.hpp"

std::tuple<bool, int *, int *> SummanddsInArray(int *arr, int n, int sum) {
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?

HOMEWORK_1
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.

давай файл переименуем

@Lynech
Copy link
Copy Markdown
Author

Lynech commented Mar 30, 2024

attempt 4

Comment thread task_01/src/test.cpp
int m = 11;
std::optional<std::tuple<int*, int*>> a = SummanddsInArray(arr, n, m);
ASSERT_TRUE(a);
ASSERT_EQ(*std::get<0>(a.value()) + *std::get<1>(a.value()), m);
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.

имхо так лучше выглядит: ASSERT_EQ(*a->first + *a->second, m);

Comment thread task_01/src/summandds_in_array.hpp Outdated
@@ -0,0 +1,9 @@
#ifndef TOPOLOGY_SORT_HPP
#define TOPOLOGY_SORT_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.

давай в соответствии с именем файла переименуем

now it's SUMMANDDS_IN_ARRAY_HPP
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