To be specific, we'll study four inductive definitions: natural numbers, linked list, binary search tree and red-black tree.
For natural numbers and linked list, we've offered you the code, and your job is to read the code carefully and make sure you fully understand every line, and then be able to answer the questions.
For binary search tree, you should write your code from scratch, based on the interface we offered you.
The last problem red-black tree is optional.
linkedList.c
, is there
any loop statement, such as while
or for
?
Then how the work is done? Take the function
linkedListInsert
at line 68 to explain your concusion.linkedList.c
, line 86, the
function linkedListInsertHead
call function
linkedListInsert
to accomplish the work. Modify
the function linkedListInsert
so as not to call
other functions, except for itself (recursion).main.c
, line 20. Can we change this
line from
m = linkedListInsertTail (m, natFromInt (i));to the following one?
linkedListInsertTail (m, natFromInt (i));Why or why not?
bst.c
, by substituting
every TODO
statement with your code. Make sure to test your
implementation when finished.
typedef struct rbtStruct *rbt; struct rbtStruct { enum rbtKind {EMPTY, RED, BLACK} kind; union { struct { poly data; rbt left; rbt right; } node; } u; };