Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

(b) Test the quadratic model for lack of fit.

Answered: 1 week ago