IT Community - Software Programming, Web Development and Technical Support

An Iterator class

This is a discussion on An Iterator class within the C and C++ Programming forums, part of the Software Development category; An Iterator class A class that is used to traverse through the objects maintained by a container class. There are ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-21-2007, 03:38 AM
vijayanand vijayanand is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 293
vijayanand is on a distinguished road
Default An Iterator class

An Iterator class

A class that is used to traverse through the objects maintained by a container class. There are five categories of iterators:
 input iterators,
 output iterators,
 forward iterators,
 bidirectional iterators,
 random access.
An iterator is an entity that gives access to the contents of a container object without violating encapsulation constraints. Access to the contents is granted on a one-at-a-time basis in order. The order can be storage order (as in lists and queues) or some arbitrary order (as in array indices) or according to some ordering relation (as in an ordered binary tree). The iterator is a construct, which provides an interface that, when called, yields either the next element in the container, or some value denoting the fact that there are no more elements to examine. Iterators hide the details of access to and update of the elements of a container class.
The simplest and safest iterators are those that permit read-only access to the contents of a container class. The following code fragment shows how an iterator might appear in code:
cont_iter:=new cont_iterator();
x:=cont_iter.next();
while x/=none do
...
s(x);
...
x:=cont_iter.next();
end;
In this example, cont_iter is the name of the iterator. It is created on the first line by instantiation of cont_iterator class, an iterator class defined to iterate over some container class, cont. Succesive elements from the container are carried to x. The loop terminates when x is bound to some empty value. (Here, none)In the middle of the loop, there is s(x) an operation on x, the current element from the container. The next element of the container is obtained at the bottom of the loop.
__________________

J.Vijayanand
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Debug class and Trace class simplesabita Software Testing 3 08-18-2007 12:30 AM
Can we inherit the java class in C# class vigneshgets C# Programming 1 08-09-2007 07:42 AM
Difference between enumeration and iterator in java? kingmaker Java Programming 3 08-08-2007 03:53 AM
Is there any way to use keyPressed method of Canvas class in Form class? bluesky Mobile Software Development 1 07-25-2007 06:02 AM
What is super class sub class in error? santoshmalvi Software Testing 1 04-16-2007 01:20 AM


All times are GMT -7. The time now is 09:25 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0