Add files via upload - #1
Conversation
| @@ -0,0 +1,151 @@ | |||
| #include<cstdio> | |||
| #include<iostream> | |||
| template<typename T> void Swap(T& elem1, T& elem2) { | |||
There was a problem hiding this comment.
Стандартный чем не устраивает?
There was a problem hiding this comment.
Меньше библиотек подключать
| @@ -0,0 +1,151 @@ | |||
| #include<cstdio> | |||
There was a problem hiding this comment.
Пробелы после слова include
| } | ||
|
|
||
| template <typename T> class Point { | ||
| public: |
There was a problem hiding this comment.
Пробел перед public не нужен.
There was a problem hiding this comment.
Хорошо, просто раньше pcf ругался, если не ставить
| elem2 = other; | ||
| } | ||
|
|
||
| template <typename T> class Point { |
|
|
||
| template<typename T> class List { | ||
| public: | ||
| const size_t size() { |
There was a problem hiding this comment.
const перед size_t не нужен, зато нужен после size()
|
|
||
| size_t length_first = 1, length_second = 1; | ||
| Point<T> *cur, *mid1, *mid2, *cur1, *cur2, *fail; | ||
| for (cur = first; cur != last; ++length_first) { |
There was a problem hiding this comment.
Можно посчитать length_first/second за O(1), если передавать в функцию сортировки сам список.
| cur1 = first->next; | ||
| cur2 = mid2; | ||
| fail = mid1->next; | ||
| while ((cur1 != fail) || (cur2 != last)) { |
There was a problem hiding this comment.
Слишком много лишних скобок
|
|
||
| cur->next = last; | ||
| cur = first; | ||
| while ((cur->next != last) && (cur->next->val < cur->val)) { |
There was a problem hiding this comment.
Зачем нужны этот и следующий блоки кода?
| cur->next = last; | ||
| cur = first; | ||
| while ((cur->next != last) && (cur->next->val < cur->val)) { | ||
| Swap(cur->next->val, cur->val); |
There was a problem hiding this comment.
Нигде не гарантируется, что тип T вообще можно свапать.
| @@ -0,0 +1,151 @@ | |||
| #include<cstdio> | |||
| #include<iostream> | |||
| template<typename T> void Swap(T& elem1, T& elem2) { | |||
There was a problem hiding this comment.
Пустая строка после инклудов
|
UPD |
| return sizeVal; | ||
| } | ||
|
|
||
| List(size_t sizeVal, Node<T> *first, Node<T> *last) { |
There was a problem hiding this comment.
Почитай про списки инициализации:
http://en.cppreference.com/w/cpp/language/initializer_list
| Point<T> *left, *right; | ||
| size_t size_val; | ||
| Node<T> *first, *last; | ||
| size_t sizeVal; |
There was a problem hiding this comment.
size_ лучше, чем sizeVal
| while (cur != ans.end()) { | ||
| out << cur->val << ' '; | ||
| cur = cur->next; | ||
| template <typename T> std::ostream& operator << (std::ostream& out, const List<T> &outVal) { |
There was a problem hiding this comment.
Можно просто val, outVal не добавляет смысла.
template здесь и в других местах лучше перенести на предыдущую строчку.
| right->next = new Point<T>(val); | ||
| right = right->next; | ||
| ++size_val; | ||
| Node<T> *nextHead = first, *head; |
There was a problem hiding this comment.
Не нужно объявлять в одной строке несколько указателей, можно случайно допустить ошибку вида
Node* a, b;
|
|
||
| Point<T>* end() const { | ||
| return right; | ||
| Node<T>* end() const { |
There was a problem hiding this comment.
Читай комментарий к предыдущей версии. end() не должен возвращать последний элемент.
| cur1 = cur; | ||
| cur = cur->next; | ||
| delete(cur1); | ||
| if (first == NULL) { |
|
|
||
| template <typename T> void Sort(Point<T> *first, Point<T> *last) { | ||
| if (first == last) | ||
| template <typename T> void Sort(List<T>& sortList) { |
There was a problem hiding this comment.
Зачем слово sort в названии параметра?
| if (first->next == last) { | ||
| if (first->val > last->val) { | ||
| Swap(first->val, last->val); | ||
| if (sortList.size() == 2) { |
There was a problem hiding this comment.
Зачем отдельно обрабатывать случай с двойкой?
| 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); |
There was a problem hiding this comment.
Сюда и далее бы переводов строк навставлять между логическими блоками, а то читается очень тяжело.
| if (cur->val > max_val) { | ||
| Swap(cur->val, max_val); | ||
| auto tail = head; | ||
| while ((headFirst != firstList.end()) || (headLast != lastList.end())) { |
There was a problem hiding this comment.
Скобки вокруг выражений лишние.
No description provided.