Skip to content

Conversation

@Lynech
Copy link

@Lynech Lynech commented Feb 23, 2024

attempt 1

attempt 1
@@ -1 +1,16 @@
#include "topology_sort.hpp"

std::tuple<bool, int *, int *> topology_sort(int *arr, int n, int m) {
Copy link
Contributor

Choose a reason for hiding this comment

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

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

#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
Contributor

Choose a reason for hiding this comment

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

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


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
Contributor

Choose a reason for hiding this comment

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

не 1 а true

#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
Contributor

Choose a reason for hiding this comment

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

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

begin++;
if ((!begin) || (!end) || (begin >= end) || (*begin + *end != sum)) {
begin = end = nullptr;
found = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

found = true;

@@ -1 +1,16 @@
#include "topology_sort.hpp"

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

Choose a reason for hiding this comment

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

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

@Lynech
Copy link
Author

Lynech commented Mar 30, 2024

attempt 4

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
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);

@@ -0,0 +1,9 @@
#ifndef TOPOLOGY_SORT_HPP
#define TOPOLOGY_SORT_HPP
Copy link
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