• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with an Iterator question

 
Ranch Hand
Posts: 91
IntelliJ IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been learning Java for 5-6 months, my friend passed me this question regarding iterator for the first time in my life I have no clue what this means, can someone help me?



[Fixed code tags and formatting - see UseCodeTags for details]
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Jim Fields,

Welcome to CodeRanch!

Please, UseCodeTags. I can see a closing code tag, however, since, there is no opening code tag, the code snippet is quite difficult to read.

Also, please TellTheDetails. What exact part you are having trouble with? And what way of thinking you are following as of now?

I hope this helps.
 
Ranch Hand
Posts: 30
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jim, The code itself doesn't make sense, since mostly no usable body in it.
What it is actually tying to do is, create a customized Iterator class, but lack of body code, nothing more.
All the collection interfaces implements Iterator, and tats just enough for normal use.

Next time try to post your code bit formatted
 
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jim. Welcome to the Ranch!

OK, what you've got there is a skeleton implementation of a custom Iterator. It looks like it's intended to wrap an existing iterator and add some additional functionality. Although as far as I can tell at first glance the additional functionality is just to optionally eliminate duplicates.

So the first question is, do you know what an Iterator is? If not, you need to read about those. If you do, you need to work out how to implement this one - you need to delegate to the wrapped Iterator, but then add whatever additional logic you need. What I'd suggest is as a first step get it delegating completely, so your Iterator works exactly the same as the one passed in. Then worry about the duplicates once you've got that working.

(A quick observation: getting a rough solution looks relatively straightforward. Getting a perfect one not so simple - I can see one tricky point).
 
Vineeth Menon
Ranch Hand
Posts: 91
IntelliJ IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for the input guys, I guess I need to find out a way to implement the iterator functionality in this skelital implementation of this iterator...is that it???
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my solution:

[Moderator action: Solution removed. This site is NotACodeMill.(⇐click)]
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vineeth Menon wrote:Thanks a lot for the input guys, I guess I need to find out a way to implement the iterator functionality in this skelital implementation of this iterator...is that it???



Well, since we have:


I would say, yes, you need to do exactly that, as it appears to be the whole point of the exercise.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sammy Wilson, welcome to the Ranch

Please note what it says on the contents page for this forum:

We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.

That is why Jeff removed your post: it does not help people to be given too complete a solution too quickly.
reply
    Bookmark Topic Watch Topic
  • New Topic