/** * prob3.c * Sam's quick test of the code in problem 3. */ // +---------+-------------------------------------------------------- // | Headers | // +---------+ #include "hashtable.h" #include // +---------+-------------------------------------------------------- // | Helpers | // +---------+ static void backwards (struct hashtable *table, char *value) { char *key = find_key (table, value); if (key == NULL) printf ("%s has no corresponding key.\n", value); else printf ("%s's key is %s.\n", value, key); } static void counter (struct hashtable *table, char *value) { int count = count_values (table, value); printf ("%s appears %d times.\n", value, count); } // counter // +------+----------------------------------------------------------- // | Main | // +------+ int main () { struct hashtable *table = new_hashtable (10); if (table == NULL) return 1; // The legendary hero/sidekick table assign (table, "Asterix", "Obelix"); assign (table, "Scooby-Doo", "Shaggy"); assign (table, "Bugs Bunny", "Daffy Duck"); assign (table, "Rocky", "Bullwinkle"); assign (table, "Bullwinkle", "Rocky"); assign (table, "Mr. Peabody", "Sherman"); assign (table, "Secret Squirrel", "Morocco Mole"); assign (table, "Yogi Bear", "Booboo Bear"); assign (table, "Batman", "Robin"); assign (table, "Blondie", "Dagwood"); assign (table, "Sandwich", "Dagwood"); assign (table, "Bart Simpson", "Milhouse Van Housen"); // Now let's print it out. print_table (table); // And check key/value pairs backwards (table, "Dagwood"); backwards (table, "Obelix"); backwards (table, "Superman"); backwards (table, "Bart Simpson"); // Check count-values , too counter (table, "Dagwood"); counter (table, "Obelix"); counter (table, "Nobody"); // We're done return 0; } // main ()