/** * collection-expt-2.c * Experiments with linear structures, particularly the copy command. */ // +---------+-------------------------------------------------------- // | Headers | // +---------+ #include #include "collection.h" #include "expt.h" // +---------+-------------------------------------------------------- // | Helpers | // +---------+ /** * Print information about a collection. */ #define PRINT_INFO(COLLECTION) \ do \ { \ PRINT_INT (collection_size (COLLECTION)); \ PRINT_INT (collection_is_empty (COLLECTION)); \ PRINT_INT (collection_is_full (COLLECTION)); \ } \ while (0) // +------+----------------------------------------------------------- // | Main | // +------+ int main () { struct collection *stuff; struct collection *ffuts; char *result; EXPERIMENT (stuff = new_collection (4)); // Add a few things to the collection EXPERIMENT (collection_put (stuff, "adam")); EXPERIMENT (collection_put (stuff, "barb")); EXPERIMENT (collection_put (stuff, "chas")); EXPERIMENT (collection_put (stuff, "dawn")); // Make a copy of the collection EXPERIMENT (ffuts = collection_copy (stuff)); // Check the size PRINT_INFO (stuff); PRINT_INFO (ffuts); // Check the elements of the copy while (! collection_is_empty (ffuts)) { EXPERIMENT (result = collection_get (ffuts)) PRINT_STR (result); } // Check the size PRINT_INFO (stuff); PRINT_INFO (ffuts); // And we're done. return 0; } // main