Results 1 to 4 of 4
  1. #1
    TopNFalvors is offline Member
    Join Date
    Mar 2011
    Posts
    41
    Rep Power
    0

    Default linked list iterator

    Hi,

    I have a generic doubly linkedList with an iterator.

    I can iterate through the list from start to last, but is there a way to iterate from last to start?

    Thanks!

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    2 choices

    Create a separate Iterator to traverse backwards.

    Modify you current Iterator to take a boolean parameter in the constructor which determines which direction to traverse. Then when you call next use an if statement to determine to get next or previous.

  3. #3
    TopNFalvors is offline Member
    Join Date
    Mar 2011
    Posts
    41
    Rep Power
    0

    Default

    Thanks...but how do you actually make it go in reverse?

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    You said your list was doubly linked. This means that each node has a previous. So instead of doing node.next you do node.previous. Try and write some code, play around with it. When you get stuck post your code, error messages, explain behaviour, ask a specific question.

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2011, 10:34 AM
  2. Linked list inside a linked list
    By viperlasson in forum New To Java
    Replies: 5
    Last Post: 07-26-2010, 11:15 PM
  3. Replies: 2
    Last Post: 12-17-2009, 04:06 PM
  4. [SOLVED] Writing an Iterator method in a custom list
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 02-12-2009, 06:22 AM
  5. Creating an Iterator for Linked List
    By spanky in forum New To Java
    Replies: 3
    Last Post: 10-05-2008, 07:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •