CS112_30_Slides-Iterators

CS112_30_Slides-Iterators - Iterators Yinglin Wang CS...

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

View Full Document Right Arrow Icon
CS112 Fundamentals of Programming Abstractions Iterators Yinglin Wang CS Dept., SJTU CS112 Fundamentals of Programming Abstractions Review Before moving to our next topic, we will review exactly what the functionMapSymbolTable does.
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS112 Fundamentals of Programming Abstractions Review Here is the typedef for the class of callback functions accepted by MapSymbolTable, and the prototype for MapSymbolTable. CS112 Fundamentals of Programming Abstractions Review When we call MapSymbolTable, we provide a function as the first argument. What MapSymbolTable does is make calls of that function on our behalf. Each call receives as its arguments a key, the corresponding value, and the clientData pointer. MapSymbolTable(NumStudentsFn, cs112SymTab, &total);
Background image of page 2
CS112 Fundamentals of Programming Abstractions Review MapSymbolTable() traverse all the keys and values pairs and pass them to the callback function as its arguments. It is difficult to show that the value arguments are in this case pointers to integers, so we have just written the word "value" as the second argument. You should understand that in the first call, for example, the second argument is the pointer to the integer 1 that is the value for the key "A". CS112 Fundamentals of Programming Abstractions Mapping functions are nice, but sometimes we want to just think like a client. It would be nice if, from the client side, we could apply a function to the keys in a symbol table.
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS112 Fundamentals of Programming Abstractions
Background image of page 4
Image of page 5
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 / 10

CS112_30_Slides-Iterators - Iterators Yinglin Wang CS...

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

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