#include #include #include #define N 10 /*-------------------------------------------------------------------*/ /* Definition of new types */ enum bool { FALSE = 45, TRUE = 73 }; typedef enum bool Bool; typedef int Index; typedef int Item; /* The content of the list */ typedef Index List; struct cell { Item value; List next; }; typedef struct cell Cell; typedef Cell Memory[N]; Memory memory; const List nil = -1; Index next_empty_cell_index = 0; /*-------------------------------------------------------------------*/ /* Function definition */ /* Provide the next index available in Memory */ Index allocate(void) { //... } /* Add value x to list l */ List cons(Item x, List l) { //... } Bool is_empty(List l) { //... } Item head(List l) { //... } List tail(List l) { //... } /*************** Derived functions ****************/ void print(List l) { //... } int length(List l) { //... } Bool search(Item x, List l) { //... } int count(Item x, List l) { //... } /*-------------------------------------------------------------------*/ /* Main Program */ int main(int argc, char **argv) { Item x; int i, k; List l; l = cons(1, cons(2, cons(3, nil))); print(l); l = tail(l); print(l); if (argc == 2) { k = atoi(argv[1]); /* convert the first argument into an integer */ assert(k > 0); } else k = 5; for (i = 1; i < k; i++) { l = cons(i, l); print(l); } printf("Length of the list: %d\n", length(l)); x = 7; if (search(x, l) == TRUE) printf("Element %d is in the list\n", x); else printf("Element %d is NOT in the list\n", x); x = 3; printf("Element %d occurs %d times in the list\n", x, count(x, l)); return 0; }