CSC161 2010F, Class 52: Building Stacks and Queues from Arrays Overview: * Exam 3 * Review * Improv Lab Admin: * EC for Tuesday's cool movie * EC for tonight's Latin American Jazz Ensemble Thingy * EC for collegium compline thingy at the red-door church across the street from bucksbaum 7 pm Sunday night * EC for freenet sunday * EC for responsible drinking (or non-drinking) before and after Waltz Questions: * I am confused about when to use malloc and when not to. * (1) When you are creating a new structure and you want it to live beyond the current procedure, you use malloc. * (2) You can also allocate with strdup and strndup (and a few other functions). You use these in the same cases. * (3) You can use malloc or strdup or strndup for allocating strings. * (4) You can only use malloc for arrays, structs, * Why would you use malloc instead of declaring a global variable? * When you are likely to make/need more than one copy. * When we built hash tables, we used strdup to make a copy of the key/value, but when we built lists, we just copied the pointer. Why? * Intent of the designer * When should we free memory? * When you know that you are done with it What did we do on Wednesday? * Stacks * Queues * Generalized Linear Collections * Other policies * Implemented array-based queues 0. Copy the stuff from Examples/Linear (use the tar file if you'd like) 1. Read the collection-expt.c and figure out what you expect the output to be. 2. Compile and run to verify. 3. The output will be borken. Why? Fix! 4. The recommended_capacity is ignored. Stop ignoring it. 5. In the test, I regularly write EXPERIMENT (result = collection_get (stuff)); PRINT_STR (result); Why don't I write? PRINT_STR (collection_get (stuff)); 5. Implement stacks. (Framework is there.)