CSC 7000-002 Algorithms & Programming
Fall 1999, Mendel 115
Dr. David Matuszek
A few people have expressed confusion about just how to do this assignment. Here are some more specific guidelines.
First, create a struct named
cellwith three fields, as follows:struct cell{char *english; char *german; struct cell *next;}; typedef struct cell cell;Next, write the following routines:
cell *create_list (); cell *add (char *english_word, char *german_word, cell *list); char *find (char *english_word, cell *list);
Here you write the necessary code to define a linked list. The struct cell defines
a block of storage with room for two pointers to strings and a pointer to another
struct cell. The function create_list() "creates" an empty
list (which is very little work!), and the function add() will
malloc() space for the cell,malloc() some more space and make copies of the two strings
(why?),The function find() just searches a list for the English word and returns
the corresponding German word.
Define a type
dictionaryas follows:typedef cell *dictionary[26];Write the following routines:
void add_to_dictionary (char *english_word, char *german_word, dictionary dict); char *look_up (char *english_word, dictionary dict);
A dictionary is an array of 26 locations, each of which is a pointer to a linked list.
To add an entry to the dictionary, add it to the correct linked list. To find the correct
linked list, do some arithmetic: chars are a kind of integer, so
(letter - 'a') is all you need. Once you've determined the correct array
location, adding the entry is no work at all, just use add(). Similarly,
looking up an entry should be no work at all.
Your main program:
Note that the main program talks to the dictionary routines, and the dictionary routines talk to the linked-list routines, but the main program doesn't talk to the linked list routines.
Reasonable variation: you might decide that it makes more sense to have
add_to_dictionary() make copies of the strings, rather than add().