CS112_43_Assignment6A - CS112 Assignment 6A Iterators...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS112 Assignment 6A Iterators Problem 1: Implementing an Iterator In lecture, we mentioned that iterators are not unique to symbol tables, but in fact can be useful for other container ADTs. Consider the queue; one of the standard ways that we work with queues is to examine each element, rotating the queue. This can be annoying when we are searching for something, as we have to finish the rotation even if we ’ve found what we needed half way through. What we really would like to be able to do is analyze each element in turn, but not worry about changing the contents of the queue. In this problem, your job is to implement a queueIteratorADT , an iterator for the queueADT . For this problem, we will assume the ring buffer implementation of the queueADT . Recall the definition of the CDT for the ring buffer implementation: struct queueCDT { queueElementT elements[QueueArraySize]; int head; int tail; } a) Because the iterator is a client of the queueADT , it doesn ’ t have access to the internal memory of the queue. Even though we could rotate the queue to build the list of each element, rotation is what we wanted to avoid in the first place. Instead, we will adopt an approach more like the symbol table, which will also make the iterators of the two match more closely. For the symbol table, we use a mapping function with MapSymbolTable to build the list. To do this with the queue, we need a new function in the queue interface, MapQueue . Write this implementation side function of the queue. b)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/06/2010 for the course CS 112 taught by Professor Yinlinwang during the Spring '08 term at Shanghai Jiao Tong University.

Page1 / 4

CS112_43_Assignment6A - CS112 Assignment 6A Iterators...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online