Thread: Iterator Question - interesting

  1. #1
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187

    Iterator Question - interesting

    ONE Linked List is being visited by 2 iterators,

    list<Field *>::iterator i = FieldList.begin();

    and

    list<Field *>::reverse_iterator rv = FieldList.rbegin();

    The Method uses a different one depending
    on the incoming parameters.

    But.. in the end of the function, it can only refer to one of the like ( (*i)->DisplayFunction(); ),

    lets say function started out using rv.

    I'll need to change rv (reverse_iterator ) into i (iterator )

    How can i do that ? or is there a better (professional) way ....

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    I think we're going to need an explanation of what you're trying to do. Why to you need to use two different iterator types at the same time?

  3. #3
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    The reverse one is used because i have to find the last instance of a the datatype i made held in the list with an 'on' flag.

    If it's possible that you can change the type of the iterator then change it back that would be great, can you do that.

    ..or..

    start with i then use rv but then put i in rv's place.
    .................................
    or something close

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    The normal way of checking for the end of a list is using the end member function.

    list<Field *>::iterator end = FieldList.end();

    This will give you one past the end of the list (used a a sentinel).

    If you wanted a faster way of reaching the last the last item added to the list without iterating from the start then you could try -

    end--;

    Then you wouldn't have to try an convert between iterator types.

  5. #5
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    Sorensen, Thanks a ton for the help .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A few interesting tools...
    By Mad_guy in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-10-2009, 06:07 PM
  2. Interesting english
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 04-27-2004, 01:24 PM
  3. Interesting number theory problem
    By Zach L. in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 09-20-2003, 07:45 AM
  4. very interesting.....VERY interesting
    By Aran in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 08-16-2002, 10:02 PM
  5. Most Interesting Commercial
    By Yoshi in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2002, 11:48 PM