Iterador

De la Viquipèdia, l'enciclopèdia lliure

En programació d'ordinadors, un iterador és un objecte que permet al programador recórrer un contenidor.[1][2][3] Sovint, la interfície del contenidor proporciona diferents tipus d'iteradors. Tot i que la interfície i la semàntica d'un cert iterador són fixes, la implementació de l'iterador depèn sovint de l'estructura de dades emprada per implementar el contenidor. Això fa que hi hagi un fort acoblament entre l'iterador i el contenidor per tal de proveir la semàntica operacional de l'iterador. Cal tenir en compte que un iterador permet recórrer un contenidor i accedir als seus elements, però no realitza la iteració. Quant al seu comportament, un iterador s'assembla a un cursor d'una base de dades. El llenguatge de programació CLU fou el primer que implementà iteradors pel volts del 1975.[4]

Referències[modifica]

A Wikimedia Commons hi ha contingut multimèdia relatiu a: Iterador
  1. «Understanding and Using Iterators» (en (anglès)). Perl.com. Arxivat de l'original el 2012-08-06. [Consulta: 8 agost 2012]. «A user-defined iterator usually takes the form of a code reference that, when executed, calculates the next item in a list and returns it. When the iterator reaches the end of the list, it returns an agreed-upon value.»
  2. «A Technique for Generic Iteration and Its Optimization» (PDF) (en (anglès)). The University of Western Ontario, Department of Computer Science. Arxivat de l'original el 2012-08-06. [Consulta: 8 agost 2012]. «Iterators were introduced as constructs to allow looping over abstract data structures without revealing their internal representation.»
  3. [Allain]. «STL Iterators» (en (anglès)). Cprogramming.com - Your resource for C and C++. [Consulta: 8 agost 2012]. «You can think of an iterator as pointing to an item that is part of a larger container of items.»
  4. Liskov, Barbara (1996). "A history of CLU". Bergin,Jr., Thomas J. and Gibson,Jr., Richard G. History of programming languages-II: 471-510, New York, NY, USA: ACM. DOI:10.1145/234286.1057826 [Consulta: 6 juny 2013] (en (anglès))