Question
2.3 Building your database First thing to do is to add buildings in your tree structure. Question 1. (14 points) First, code addBuilding. The argument
2.3 Building your database First thing to do is to add buildings in your tree structure. Question 1. (14 points) First, code addBuilding. The argument is the OneBuilding that you want to add to the tree structure. Given a Building b and a OneBuilding obToAdd, b.addBuilding(obToAdd) adds the OneBuilding obToAdd in the tree with root b accordingly to the rules explained before : if obToAdd is older (resp. younger) than b.data, it has to be added (in the appropriate place) to the subtree b.older (resp. b.younger). if obToAdd is the same age as b.data, then it depends on the height : if obToAdd is strictly higher than b.data, it becomes the new root and you have to adapt the other elds accordingly. To clarify, let us give some examples. At the nodes of the tree, you will see (for instance) b1(1987; 50). This means Building b1 has data.yearOfConstruction 1987 and data.height 50. When the elds older, same or younger are not null, we represent them with an arrow to the corresponding Building. Let us start with the following tree : b1(1987; 50) b1:older v b1:younger ( b6(1985; 60) b6:same b2(1988; 60) b2:younger ( b4(1985; 50) b4:same b8(1995; 55) b5(1985; 45) Now, if we have a One Building ob3 with yearOfConstruction 1987, height 55, the command b1.addBuilding (ob3) should return a Building where 4 the root b3 has data ob3 and the elds should have been updated to : b3(1987; 55) b3:older v b3:same b3:younger ( b6(1985; 60) b6:same b1(1987; 50) b2(1988; 60) b2:younger ( b4(1985; 50) b4:same b8(1995; 55) b5(1985; 45) If OneBuilding ob7 has yearOfConstruction 1986 and height 55, then the command b3.addBuilding(ob7) should return b3 and the tree structure should be updated to : b3(1987; 55) b3:older s b3:same b3:younger ( b6(1985; 60) b6:same b6:younger ( b1(1987; 50) b2(1988; 60) b2:younger ( b4(1985; 50) b4:same b7(1986; 55) b8(1995; 55) b5(1985; 45) with b7.data = ob7.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started