exam 3 definitions and code questions Flashcards
(78 cards)
what are the private variables of the Itr class?
dnode<T>* current</T>
what are the public members of the dnode class used in the Itr class?
T data;
dnode<T>* next;
dnode<T>* prev;</T></T>
what is the relationship of the List class to the iterator class?
the List class is declared a friend class of Itr in its public section
write the in-line definition of the default constructor for the Itr class
Itr(): current(0) {};
write the in-line definition of the constructor that takes a dnode parameter for the Itr class
Itr(dnode<T> *ptr): current(ptr) {};</T>
write the in-line non-const operator* (functions as the dereference operator) for the Itr class
T& operator*() {return current->data;};
write the in-line const operator* (functions as the dereference operator) for the Itr class
T operator*() {return current->data;};
what is the difference in the function definitions for ++i and i++ (also –i and i–) for the Itr class?
i++ and i– have an int dummy parameter to let the compiler know it is ++i and not i++. Also, all the pre-increments return a reference, and all the post-increments do not.
write the in-line definition for the pre-increment operator for the Itr class
Itr<T>& operator++() {
if(current) current = current ->next;
return *this;
}</T>
write the in-line definition for the post-increment operator for the Itr class
Itr<T> operator++(int){
Itr<T> result = current;
if(current) current = current->next;
return result;
}</T></T>
write the in-line definition for the pre-decrement operator for the Itr class
Itr<T>& operator--(){
if(current) current = current->prev;
return *this;
}</T>
write the in-line definition for the post-decrement operator for the Itr class
Itr<T> operator--(int){
Itr<T> result = current;
if(current) current = current->prev;
return result;
}</T></T>
what requirements need to be met in order to overload the points at (->) operator?
in order to overload, the operator must be a method, not a free function, and must return a pointer or object of that class
write the in-line definition for the non-const points to operator (operator->) for the Itr class
dnode<T>* operator->() {return current;};</T>
write the in-line definition for the const points to operator (operator->) for the Itr class
const dnode<T>* operator->() {return current;};</T>
write the in-line definition of the operator== for the Itr class
bool operator==(Itr<T> rhs) const {return current == rhs.current;};</T>
write the in-line definition of the operator!= for the Itr class
bool operator!=(Itr<T> rhs) const {return !(current == rhs.current);</T>
what are the private variables of the List class?
dnode<T>* beginning;
dnode<T>* ending;</T></T>
write the in-line default constructor for the List class
List(): beginning(0), ending(0) {};
write the in-line operator= for the List class
operator= (List<T> rhs) {swap(rhs); return *this;};</T>
write the in-line definition for the function isEmpty for the List class
bool isEmpty() const {return beginning == 0;};
write the non-const in-line definition for the function begin for the List class that returns an iterator pointing to the beginning of the list.
Itr<T> begin() {return Itr<T>(beginning);};</T></T>
write the const in-line definition for the function begin for the List class that returns an iterator pointing to the beginning of the list.
const Itr<T> begin() const {return Itr<T>(beginning);};</T></T>
write the non-const in-line definition for the function end for the List class that returns an iterator pointing to the ending of the list.
Itr<T> end() {return Itr<T>(ending);};</T></T>