-
Notifications
You must be signed in to change notification settings - Fork 15
HOMEWORK 1 #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
HOMEWORK 1 #11
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
#include <iostream> | ||
|
||
int main() { return 0; } | ||
#include "topology_sort.hpp" | ||
|
||
int main() { | ||
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; | ||
int m = 5; | ||
std::tuple<bool, int*, int*> b = SummanddsInArray(a, 9, m); | ||
if (std::get<0>(b)) { | ||
std::cout << "found" << std::endl; | ||
std::cout << std::get<1>(b) << " : " << *std::get<1>(b) << std::endl; | ||
std::cout << std::get<2>(b) << " : " << *std::get<2>(b) << std::endl; | ||
} else | ||
std::cout << "NOT found" << std::endl; | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. давай файл переименуем |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
#include "topology_sort.hpp" | ||
|
||
std::tuple<bool, int *, int *> SummanddsInArray(int *arr, int n, int sum) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. сомнительный конечно тип возвращаемого значения, может тогда лучше std::optional? |
||
int *begin = arr, *end = arr + (n - 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. давай делать так: одна строка одно объявление |
||
bool found = true; | ||
while (begin && end && begin < end && *begin + *end != sum) | ||
if ((*begin + *end) > sum) | ||
end--; | ||
else | ||
begin++; | ||
if ((!begin) || (!end) || (begin >= end) || (*begin + *end != sum)) { | ||
begin = end = nullptr; | ||
found = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. found = true; |
||
} | ||
return std::tuple<bool, int *, int *>{found, begin, end}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
#pragma once | ||
#ifndef TOPOLOGY_SORT_HPP | ||
#define TOPOLOGY_SORT_HPP | ||
|
||
#include <tuple> | ||
|
||
std::tuple<bool, int*, int*> SummanddsInArray(int* arr, int n, int m); | ||
|
||
#endif |
Uh oh!
There was an error while loading. Please reload this page.