Skip to content

Add files via upload - #1

Open
igoroogle wants to merge 2 commits into
masterfrom
igoroogle-patch-1
Open

Add files via upload#1
igoroogle wants to merge 2 commits into
masterfrom
igoroogle-patch-1

Conversation

@igoroogle

Copy link
Copy Markdown
Owner

No description provided.

@igoroogle
igoroogle requested a review from ifsmirnov December 25, 2017 21:07
Comment thread main.cpp
@@ -0,0 +1,151 @@
#include<cstdio>
#include<iostream>
template<typename T> void Swap(T& elem1, T& elem2) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Стандартный чем не устраивает?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Меньше библиотек подключать

Comment thread main.cpp
@@ -0,0 +1,151 @@
#include<cstdio>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Пробелы после слова include

Comment thread main.cpp
}

template <typename T> class Point {
public:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Пробел перед public не нужен.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Хорошо, просто раньше pcf ругался, если не ставить

Comment thread main.cpp
elem2 = other;
}

template <typename T> class Point {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Это не Point, а Node.

Comment thread main.cpp

template<typename T> class List {
public:
const size_t size() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

const перед size_t не нужен, зато нужен после size()

Comment thread main.cpp

size_t length_first = 1, length_second = 1;
Point<T> *cur, *mid1, *mid2, *cur1, *cur2, *fail;
for (cur = first; cur != last; ++length_first) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Можно посчитать length_first/second за O(1), если передавать в функцию сортировки сам список.

Comment thread main.cpp
cur1 = first->next;
cur2 = mid2;
fail = mid1->next;
while ((cur1 != fail) || (cur2 != last)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Слишком много лишних скобок

Comment thread main.cpp

cur->next = last;
cur = first;
while ((cur->next != last) && (cur->next->val < cur->val)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Зачем нужны этот и следующий блоки кода?

Comment thread main.cpp
cur->next = last;
cur = first;
while ((cur->next != last) && (cur->next->val < cur->val)) {
Swap(cur->next->val, cur->val);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Нигде не гарантируется, что тип T вообще можно свапать.

Comment thread main.cpp
@@ -0,0 +1,151 @@
#include<cstdio>
#include<iostream>
template<typename T> void Swap(T& elem1, T& elem2) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Пустая строка после инклудов

@igoroogle

Copy link
Copy Markdown
Owner Author

UPD

Comment thread main
return sizeVal;
}

List(size_t sizeVal, Node<T> *first, Node<T> *last) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Почитай про списки инициализации:
http://en.cppreference.com/w/cpp/language/initializer_list

Comment thread main
Point<T> *left, *right;
size_t size_val;
Node<T> *first, *last;
size_t sizeVal;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

size_ лучше, чем sizeVal

Comment thread main
while (cur != ans.end()) {
out << cur->val << ' ';
cur = cur->next;
template <typename T> std::ostream& operator << (std::ostream& out, const List<T> &outVal) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Можно просто val, outVal не добавляет смысла.
template здесь и в других местах лучше перенести на предыдущую строчку.

Comment thread main
right->next = new Point<T>(val);
right = right->next;
++size_val;
Node<T> *nextHead = first, *head;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Не нужно объявлять в одной строке несколько указателей, можно случайно допустить ошибку вида

Node* a, b;

Comment thread main

Point<T>* end() const {
return right;
Node<T>* end() const {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Читай комментарий к предыдущей версии. end() не должен возвращать последний элемент.

Comment thread main
cur1 = cur;
cur = cur->next;
delete(cur1);
if (first == NULL) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nullptr

Comment thread main

template <typename T> void Sort(Point<T> *first, Point<T> *last) {
if (first == last)
template <typename T> void Sort(List<T>& sortList) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Зачем слово sort в названии параметра?

Comment thread main
if (first->next == last) {
if (first->val > last->val) {
Swap(first->val, last->val);
if (sortList.size() == 2) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Зачем отдельно обрабатывать случай с двойкой?

Comment thread main
while ((cur->next != last) && (cur->next->val < cur->val)) {
Swap(cur->next->val, cur->val);
cur = cur->next;
auto firstList = List<T>(sortList.size() / 2, sortList.begin(), midNode);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Сюда и далее бы переводов строк навставлять между логическими блоками, а то читается очень тяжело.

Comment thread main
if (cur->val > max_val) {
Swap(cur->val, max_val);
auto tail = head;
while ((headFirst != firstList.end()) || (headLast != lastList.end())) {

Copy link
Copy Markdown
Collaborator

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