/** * list-expt.c * A collection of experiments with linked lists. Link this with * an implementation of lists to see how well (or poorly) the * implementation works. */ // +---------+-------------------------------------------------------- // | Headers | // +---------+ #include #include "list.h" #include "expt.h" // +--------+--------------------------------------------------------- // | Macros | // +--------+ #define PRINT_LIST(LIST) \ BLOCK( \ fprintf (stderr, VAR_PREFIX "%s = ", #LIST); \ list_print (LIST, stderr); \ fprintf (stderr, "\n"); ) // +------+----------------------------------------------------------- // | Main | // +------+ int main () { struct list *lst; // Create the empty list. EXPERIMENT (lst = new_list()); PRINT_LIST (lst); // Add some elements to the front. EXPERIMENT (list_prepend (lst, "a")); PRINT_LIST (lst); EXPERIMENT (list_prepend (lst, "b")); PRINT_LIST (lst); // Add some elements to the end. EXPERIMENT (list_append (lst, "c")); PRINT_LIST (lst); EXPERIMENT (list_append (lst, "d")); PRINT_LIST (lst); // Check the size EXPERIMENT (printf ("Size is %d\n", list_length (lst))); // Add a duplicate element to the end. EXPERIMENT (list_append (lst, "a")); PRINT_LIST (lst); // Add another element (just for fun). EXPERIMENT (list_append (lst, "f")); PRINT_LIST (lst); // Delete a middle element. EXPERIMENT (list_delete (lst, "c")); PRINT_LIST (lst); // Delete the first element EXPERIMENT (list_delete (lst, "b")); PRINT_LIST (lst); // Delete the last element EXPERIMENT (list_delete (lst, "f")); PRINT_LIST (lst); return 0; } // main