Question
Consider the implementation of the List class in your textbook. In the Iterator class, the function Iterator::get simply returns the value of the node to
Consider the implementation of the List class in your textbook. In the Iterator class, the function Iterator::get simply returns the value of the node to which the iterator points. Given below is the code snippet for an Iterator class and the function get. What is the error in the implementation and how can it be fixed?
class Iterator
{
public:
Iterator();
string get() const;
void next();
void previous();
bool equals(Iterator b) const;
private:
Node* position;
List* container;
friend class List;
};
string Iterator::get() const
{
return next->data;
}
a) The code for the Iterator class is erroneous because the constructor for the Iterator class should be private.
b) The code for the Iterator class is erroneous because the declaration friend class List should be in the public section.
c) The get function should return container->data.
d) The get function should return next()->data.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started