/** * linear-expt.c * Experiments with linear structures. */ // +---------+-------------------------------------------------------- // | Headers | // +---------+ #include #include "collection.h" #include "expt.h" // +------+----------------------------------------------------------- // | Main | // +------+ int main () { struct collection *stuff; char *result; EXPERIMENT (stuff = new_collection (4)); // Can we create a basic collection? PRINT_INT (collection_size (stuff)); PRINT_INT (collection_is_empty (stuff)); PRINT_INT (collection_is_full (stuff)); // Can we 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")); EXPERIMENT (collection_put (stuff, "a")); EXPERIMENT (collection_put (stuff, "b")); EXPERIMENT (collection_put (stuff, "c")); EXPERIMENT (collection_put (stuff, "d")); EXPERIMENT (collection_put (stuff, "e")); PRINT_INT (collection_size (stuff)); PRINT_INT (collection_is_empty (stuff)); PRINT_INT (collection_is_full (stuff)); // Can we remove a few things? EXPERIMENT (result = collection_get (stuff)); PRINT_STR (result); EXPERIMENT (result = collection_get (stuff)); PRINT_STR (result); EXPERIMENT (result = collection_get (stuff)); PRINT_STR (result); PRINT_INT (collection_size (stuff)); PRINT_INT (collection_is_empty (stuff)); PRINT_INT (collection_is_full (stuff)); // Can we add a few more things? EXPERIMENT (collection_put (stuff, "eric")); EXPERIMENT (collection_put (stuff, "fawn")); EXPERIMENT (collection_put (stuff, "greg")); EXPERIMENT (collection_put (stuff, "hope")); PRINT_INT (collection_size (stuff)); PRINT_INT (collection_is_empty (stuff)); PRINT_INT (collection_is_full (stuff)); // Okay, let's clear out the collection while (! collection_is_empty (stuff)) { EXPERIMENT (result = collection_get (stuff)) PRINT_STR (result); } // Print info. PRINT_INT (collection_size (stuff)); PRINT_INT (collection_is_empty (stuff)); PRINT_INT (collection_is_full (stuff)); // Add a few more things (empty collections are sometimes problematic) EXPERIMENT (collection_put (stuff, "inge")); EXPERIMENT (collection_put (stuff, "jack")); EXPERIMENT (collection_put (stuff, "kate")); PRINT_INT (collection_size (stuff)); PRINT_INT (collection_is_empty (stuff)); PRINT_INT (collection_is_full (stuff)); // Okay, let's clear out the collection again while (! collection_is_empty (stuff)) { EXPERIMENT (result = collection_get (stuff)) PRINT_STR (result); } // And we're done. return 0; } // main