divyang4481 / mipt-hw

Automatically exported from code.google.com/p/mipt-hw
0 stars 0 forks source link

task01 TList (Яковенко) #181

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
iakovenko_pavel/TList

Original issue reported on code.google.com by iakovenk...@gmail.com on 26 Feb 2013 at 9:23

GoogleCodeExporter commented 9 years ago
0. Ошибки компиляции:
main.cpp:361: error: redefinition of ‘struct TList<T>::node’
main.cpp:8: error: previous definition of ‘struct TList<T>::node’
main.cpp:384: error: too few template-parameter-lists
main.cpp:385: error: too few template-parameter-lists
main.cpp: In destructor ‘TList<T>::~TList() [with T = int]’:
main.cpp:388:   instantiated from here
main.cpp:90: error: ‘struct TList<int>::node’ has no member named ‘next’
main.cpp: In member function ‘void TList<T>::push_back(T) [with T = int]’:
main.cpp:390:   instantiated from here
main.cpp:121: error: ‘struct TList<int>::node’ has no member named ‘val’
main.cpp:122: error: ‘struct TList<int>::node’ has no member named 
‘next’
main.cpp:124: error: ‘struct TList<int>::node’ has no member named 
‘prev’
main.cpp:128: error: ‘struct TList<int>::node’ has no member named 
‘prev’
main.cpp:129: error: ‘struct TList<int>::node’ has no member named 
‘next’
main.cpp: In member function ‘void TList<T>::push_front(T) [with T = int]’:
main.cpp:392:   instantiated from here
main.cpp:136: error: ‘struct TList<int>::node’ has no member named ‘val’
main.cpp:137: error: ‘struct TList<int>::node’ has no member named 
‘prev’
main.cpp:140: error: ‘struct TList<int>::node’ has no member named 
‘next’
main.cpp:143: error: ‘struct TList<int>::node’ has no member named 
‘next’
main.cpp:144: error: ‘struct TList<int>::node’ has no member named 
‘prev’
main.cpp: In member function ‘TList<T>& TList<T>::operator=(TList<T>&) [with 
T = int]’:
main.cpp:397:   instantiated from here
main.cpp:186: error: ‘struct TList<int>::node’ has no member named ‘val’
main.cpp:187: error: ‘struct TList<int>::node’ has no member named 
‘next’
main.cpp:189: error: ‘struct TList<int>::node’ has no member named ‘val’
main.cpp: In member function ‘void TList<T>::show() [with T = int]’:
main.cpp:398:   instantiated from here
main.cpp:353: error: ‘struct TList<int>::node’ has no member named 
‘next’
main.cpp:354: error: ‘struct TList<int>::node’ has no member named ‘val’
main.cpp: In member function ‘T TList<T>::pop_front() [with T = int]’:
main.cpp:405:   instantiated from here
main.cpp:159: error: ‘struct TList<int>::node’ has no member named ‘val’
main.cpp:160: error: ‘struct TList<int>::node’ has no member named 
‘next’
main.cpp:161: error: ‘struct TList<int>::node’ has no member named 
‘prev’
main.cpp:162: error: ‘struct TList<int>::node’ has no member named 
‘prev’
main.cpp: In member function ‘T& TList<T>::front() [with T = int]’:
main.cpp:407:   instantiated from here
main.cpp:169: error: ‘struct TList<int>::node’ has no member named ‘val’
main.cpp: In member function ‘T& TList<T>::back() [with T = int]’:
main.cpp:407:   instantiated from here
main.cpp:175: error: ‘struct TList<int>::node’ has no member named ‘val’
main.cpp: In member function ‘void TList<T>::clear() [with T = int]’:
main.cpp:409:   instantiated from here
main.cpp:112: error: ‘struct TList<int>::node’ has no member named 
‘next’
main.cpp: In member function ‘TList<T>::iterator 
TList<T>::iterator::operator+(int) [with T = int]’:
main.cpp:422:   instantiated from here
main.cpp:59: error: ‘struct TList<int>::node’ has no member named ‘next’
main.cpp: In member function ‘void TList<T>::splice(TList<T>::iterator, 
TList<T>&) [with T = int]’:
main.cpp:426:   instantiated from here
main.cpp:317: error: no match for ‘operator!=’ in ‘tp != 
((TList<int>*)lt)->TList<T>::begin [with T = int]()’
main.cpp:33: note: candidates are: bool 
TList<T>::iterator::operator!=(TList<T>::iterator&) [with T = int]
main.cpp: In member function ‘void TList<T>::Insert(TList<T>::node*, T) [with 
T = int]’:
main.cpp:241:   instantiated from ‘void TList<T>::insert(TList<T>::iterator, 
T) [with T = int]’
main.cpp:415:   instantiated from here
main.cpp:204: error: ‘struct TList<int>::node’ has no member named ‘val’
main.cpp: In member function ‘bool TList<T>::iterator::Last() [with T = 
int]’:
main.cpp:252:   instantiated from ‘void TList<T>::insert(TList<T>::iterator, 
TList<T>::iterator, TList<T>::iterator) [with T = int]’
main.cpp:419:   instantiated from here
main.cpp:47: error: ‘struct TList<int>::node’ has no member named ‘next’
main.cpp: In member function ‘void TList<T>::iterator::operator--() [with T = 
int]’:
main.cpp:253:   instantiated from ‘void TList<T>::insert(TList<T>::iterator, 
TList<T>::iterator, TList<T>::iterator) [with T = int]’
main.cpp:419:   instantiated from here
main.cpp:22: error: ‘struct TList<int>::node’ has no member named ‘prev’
main.cpp: In member function ‘T TList<T>::iterator::operator*() [with T = 
int]’:
main.cpp:255:   instantiated from ‘void TList<T>::insert(TList<T>::iterator, 
TList<T>::iterator, TList<T>::iterator) [with T = int]’
main.cpp:419:   instantiated from here
main.cpp:26: error: ‘struct TList<int>::node’ has no member named ‘val’
main.cpp: In member function ‘void TList<T>::iterator::operator++() [with T = 
int]’:
main.cpp:62:   instantiated from ‘TList<T>::iterator 
TList<T>::iterator::operator+(int) [with T = int]’
main.cpp:422:   instantiated from here
main.cpp:18: error: ‘struct TList<int>::node’ has no member named ‘next’
main.cpp: In member function ‘void TList<T>::Extract(TList<T>::node*) [with T 
= int]’:
main.cpp:300:   instantiated from ‘void TList<T>::erase(TList<T>::iterator) 
[with T = int]’
main.cpp:422:   instantiated from here
main.cpp:268: error: ‘struct TList<int>::node’ has no member named 
‘next’
main.cpp:270: error: ‘struct TList<int>::node’ has no member named 
‘next’
main.cpp:270: error: ‘struct TList<int>::node’ has no member named 
‘prev’
main.cpp:272: error: ‘struct TList<int>::node’ has no member named 
‘prev’
main.cpp:274: error: ‘struct TList<int>::node’ has no member named 
‘prev’
main.cpp:274: error: ‘struct TList<int>::node’ has no member named 
‘next’
main.cpp: In member function ‘void TList<T>::Insert(TList<T>::node*, 
TList<T>::node*) [with T = int]’:
main.cpp:205:   instantiated from ‘void TList<T>::Insert(TList<T>::node*, T) 
[with T = int]’
main.cpp:241:   instantiated from ‘void TList<T>::insert(TList<T>::iterator, 
T) [with T = int]’
main.cpp:415:   instantiated from here
main.cpp:210: error: ‘struct TList<int>::node’ has no member named ‘val’
main.cpp:214: error: ‘struct TList<int>::node’ has no member named 
‘prev’
main.cpp:214: error: ‘struct TList<int>::node’ has no member named 
‘prev’
main.cpp:215: error: ‘struct TList<int>::node’ has no member named 
‘next’
main.cpp:216: error: ‘struct TList<int>::node’ has no member named 
‘prev’
main.cpp:217: error: ‘struct TList<int>::node’ has no member named 
‘prev’

1. Кажется, что ~TList и clear делают одно и то же => 
copy-paste

2. Где константный итератор и 
соответствующие методы для его получения?

3. То же самое замечание про rehearsal/reserve

4. Конструктор TList(T val) - очень странный. 
Думаю конструктор копирования намного 
полезнее :)

5. Не вижу констукторов:
 * из интервала другого контейнера
 * конструктора n элементов с определенным значением

6. Конструкции вида:
  Begin=iterator(first);
  return Begin;
Можно упростить:
  return iterator(first);
Последняя работает быстрее. Почему, 
попробуйте найти объяснение сами.

7. empty должен быть константным

8. Как договаривались, в наших контейнерах 
не должно быть никаких проверок ошибок. 
Если Вам требуется отладочный вывод, 
нельзя чтобы он работал у пользователя. 
Предлагаю оборачивать его в #ifdef. Например 
так:
#ifdef DEBUG_MODE
                    if (first!=0)                                                                
                         cout <<"Error!"<<endl;
#endif
Чтобы включить отладочный вывод, 
достаточно в начале файла указать:
#define DEBUG_MODE

Original comment by aivyu...@gmail.com on 8 Mar 2013 at 8:31

GoogleCodeExporter commented 9 years ago

Original comment by iakovenk...@gmail.com on 19 May 2013 at 11:10

GoogleCodeExporter commented 9 years ago
Не собирается:

main.cpp: In function ‘void show(TList<T>&)’:
main.cpp:475: error: ISO C++ forbids declaration of ‘pos’ with no type
main.cpp:478: error: invalid type argument of ‘unary *’
main.cpp: In function ‘void show(TList<T>&) [with T = TFoo]’:
main.cpp:486:   instantiated from here
main.cpp:475: error: cannot convert ‘TList<TFoo>::const_iterator’ to 
‘int’ in initialization
main.cpp:486:   instantiated from here
main.cpp:477: error: no match for ‘operator!=’ in ‘pos != 
((TList<TFoo>*)a)->TList<T>::cend [with T = TFoo]()’

Original comment by aivyu...@gmail.com on 19 May 2013 at 11:38

GoogleCodeExporter commented 9 years ago

Original comment by iakovenk...@gmail.com on 19 May 2013 at 12:00

GoogleCodeExporter commented 9 years ago
1. Ваши operator++/operator-- возвращают void.
Это неудобно, т.к. нельзя написать такой код:
vector<int>::iterator iter = ++other_iter;
К тому же, нет постфиксных версий 
operator++/operator--.
Т.е. вот так не напишешь: iter++.

2. Что за странные методе Last/First у 
итераторов? Зачем они?

3. Ваш итератор является RandomAccess, т.к. у него 
реализован operator+. Но мы говорили, что для 
списка реализовать RandomAccess-итератор 
невозможно. Это самообман, т.к. operator+ 
работает за O(n).

4. iterator::operator* возвращает T. Как же тогда 
менять его значение?

5. Не реализован iterator::operator->

6. В задании указано, что методы, 
возвращающие итераторы нужно назвать begin и 
end. А у Вас появились какие-то cbegin/cend.
К тому же, они не константные. Значит, их 
нельзя будет вызвать у конст объекта.

7. Ваш метод swap НЕ ИМЕЕТ НИКАКОГО СМЫСЛА. Т.к. 
он делает то же самое, что и std::swap. Смысл 
реализации метода swap в том, чтобы он 
работал за O(1). А у Вас он работает за O(n).

8. Наверное, логично, если show будет 
принимать константную ссылку.

Решение не принято.

Original comment by aivyu...@gmail.com on 19 May 2013 at 12:13

GoogleCodeExporter commented 9 years ago

Original comment by iakovenk...@gmail.com on 19 May 2013 at 1:02

GoogleCodeExporter commented 9 years ago
1. Ведь это грубейшая ошибка:
 73                 iterator& operator++(){
 74                         el=el->next;
 75                         return *this;
 76                 };
 77                 
 78                 iterator& operator++(int){
 79                         el=el->next;
 80                         return *this;
 81                 }; 
Даже комментироваь не буду. Думайте сами.

2. Все еще вижу Last/First :)

3. Почему operator-> возвращает указатель?

4. void operator=

5. Вы таки не переименовали cbegin/cend в begin/end.
Напоминаю: методы с разной константностью 
считаются методами с разной сигнатурой. 
Т.е. они могут сосуществовать и считаться 
перегруженными.

6. front/back невозможно вызвать у константного 
списка.

Решение не принято.

Original comment by aivyu...@gmail.com on 19 May 2013 at 2:48

GoogleCodeExporter commented 9 years ago

Original comment by iakovenk...@gmail.com on 20 May 2013 at 4:47

GoogleCodeExporter commented 9 years ago
1. Делать метод get публичным (у итераторов) - 
плохая идея, т.к. Вы раскрываете реализацию 
класса. Пользователь может вызвать этот 
метод. Тогда Вы уже будете обязаны 
следовать своей реализации. Иначе при 
изменении Вашего кода может перестать 
компилироваться код пользователя.

2. return можно не вызывать в конце методов, 
возвращающих void. Но, конечно, это не ошибка.

3. ДОписываю в конце main() свой код 
(закоммитил):
        {
            typedef TList<TFoo> TListFoo;
            TListFoo a;
            for (int i = 0; i < 10; ++i)
                a.push_back(TFoo(i));

            TListFoo b = a;
            for (int i = 0; i < 10; ++i)
                b.push_front(TFoo(i));

            a.swap(b);
        }
Запускаю. Программа падает с проездом по 
памяти.

Решение не принято.

Original comment by aivyu...@gmail.com on 26 May 2013 at 11:07

GoogleCodeExporter commented 9 years ago

Original comment by iakovenk...@gmail.com on 26 May 2013 at 11:46

GoogleCodeExporter commented 9 years ago
Решение принято.

Original comment by aivyu...@gmail.com on 26 May 2013 at 11:51