Be sure you have read, or at least skimmed, the assigned readings for classes through 11/10.
Do the following programming problems. You will end up with at least one code file per problem. Submit your program source (and any other needed files) one of two ways:
This partial implementation consists of a number of files:
NOTE that downloading files if you're using department computers remotely is problematical. You can do this from the commmand line if you have the full URL, however, using command wget. For example, to get the ZIP file:
wget http://www.cs.trinity.edu/~bmassing/Classes/CS1120_2020spring/Homeworks/HW09/Problems/hw9.zip
NOTE that this assignment really kind of relies on your having access to make. If you're not able to make (ha!) that work, talk to me about options. It's a big help if you also have access to valgrind; if you can't easily set that up, again, talk to me about options.
Your job is to modify the file int-bst.c so it includes function definitions for all the functions declared in int-bst.h. The test program is self-contained and contains code to call the functions you will write, so you don't need to write any input/output code, aside from implementing two print functions. You compile the test program by typing make test-int-bst and run it by typing ./test-int-bst.
Note that the function that removes a single element of the tree (int_bst_remove) is optional; you can provide an “implementation” that just prints an error message, or for extra credit you can actually implement this operation.
You should not modify any other files, unless you want to add additional tests to test-int-bst.c.
Sample output of the test program:
inserting 40 into tree [ ] result [ 40 ] inserting 30 into tree [ 40 ] result [ 30 40 ] inserting 50 into tree [ 30 40 ] result [ 30 40 50 ] inserting 20 into tree [ 30 40 50 ] result [ 20 30 40 50 ] inserting 60 into tree [ 20 30 40 50 ] result [ 20 30 40 50 60 ] inserting 16 into tree [ 20 30 40 50 60 ] result [ 16 20 30 40 50 60 ] inserting 14 into tree [ 16 20 30 40 50 60 ] result [ 14 16 20 30 40 50 60 ] inserting 18 into tree [ 14 16 20 30 40 50 60 ] result [ 14 16 18 20 30 40 50 60 ] inserting 24 into tree [ 14 16 18 20 30 40 50 60 ] result [ 14 16 18 20 24 30 40 50 60 ] inserting 56 into tree [ 14 16 18 20 24 30 40 50 60 ] result [ 14 16 18 20 24 30 40 50 56 60 ] inserting 64 into tree [ 14 16 18 20 24 30 40 50 56 60 ] result [ 14 16 18 20 24 30 40 50 56 60 64 ] inserting 30 into tree [ 14 16 18 20 24 30 40 50 56 60 64 ] result [ 14 16 18 20 24 30 40 50 56 60 64 ] inserting 50 into tree [ 14 16 18 20 24 30 40 50 56 60 64 ] result [ 14 16 18 20 24 30 40 50 56 60 64 ] test data in order [ 14 16 18 20 24 30 30 40 50 50 56 60 64 ] 40 30 20 16 14 . . 18 . . 24 . . . 50 . 60 56 . . 64 . . finding 0 in tree [ 14 16 18 20 24 30 40 50 56 60 64 ] result false finding 100 in tree [ 14 16 18 20 24 30 40 50 56 60 64 ] result false finding 10 in tree [ 14 16 18 20 24 30 40 50 56 60 64 ] result false finding 40 in tree [ 14 16 18 20 24 30 40 50 56 60 64 ] result true finding 14 in tree [ 14 16 18 20 24 30 40 50 56 60 64 ] result true finding 64 in tree [ 14 16 18 20 24 30 40 50 56 60 64 ] result true removing 0 from tree [ 14 16 18 20 24 30 40 50 56 60 64 ] result [ 14 16 18 20 24 30 40 50 56 60 64 ] removing 16 from tree [ 14 16 18 20 24 30 40 50 56 60 64 ] result [ 14 18 20 24 30 40 50 56 60 64 ] removing 60 from tree [ 14 18 20 24 30 40 50 56 60 64 ] result [ 14 18 20 24 30 40 50 56 64 ] removing 30 from tree [ 14 18 20 24 30 40 50 56 64 ] result [ 14 18 20 24 40 50 56 64 ] removing 50 from tree [ 14 18 20 24 40 50 56 64 ] result [ 14 18 20 24 40 56 64 ] 40 20 14 . 18 . . 24 . . 64 56 . . . inserting 0 into tree [ 14 18 20 24 40 56 64 ] result [ 0 14 18 20 24 40 56 64 ] inserting 100 into tree [ 0 14 18 20 24 40 56 64 ] result [ 0 14 18 20 24 40 56 64 100 ] inserting 0 into tree [ 0 14 18 20 24 40 56 64 100 ] result [ 0 14 18 20 24 40 56 64 100 ] inserting 100 into tree [ 0 14 18 20 24 40 56 64 100 ] result [ 0 14 18 20 24 40 56 64 100 ] after removing all elements [ ]Output of the “print as tree” function is a bit obscure. Described recursively, it works as follows:
40 <-- root 30 <-- left child of 40 20 <-- left child of 30 16 14 . . 18 . . 24 . . . <-- right child of 30 (empty) 50 <-- right child of 40 . <-- left child of 50 (empty) 60 <-- right child of 60 56 . . 64 . .It may be worth noting that my code for “remove” does something a bit tricky that I don't really expect yours to do: For nodes with two children, one can replace the node with either the largest element to its left or the smallest to the right; my code alternates between the two. I do not expect you to do this too, so your results if you implement “remove” may differ from mine.
Hints:
What to turn in: Just send me your int-bst.c file, unless you added more tests to test-int-bst.c, in which case send that too (but be sure your code works with the provided version as well).
This should include the Honor Code pledge, or just the word “pledged”, plus at least one of the following about collaboration and help (as many as apply). Text in italics is explanatory or something for you to fill in; you don't need to repeat it!
This should be a brief essay (a sentence or two is fine, though you can write as much as you like) telling me what if anything you think you learned from the assignment, and what if anything you found interesting, difficult, or otherwise noteworthy.