subject

This will be your first foray into an actual ADT implementation. It is not a toy program, but the
real deal. You'll take the binary search tree implemented in the modules (and supplied in your
downloaded header file libraries) and modify it to use lazy deletion rather than the explicit
"hard deletion."
If you have carefully studied and experimented with the binary search tree template class, this
assignment should be "just right". It is not as difficult as doing an ADT from scratch, which might
require more than a week. Nonetheless, in the few methods that you must retool, you'll find just
enough of a challenge to feel like you are really cracking the problem. The changes and
debugging you will be doing are typical of ADT design.
Copy the file FHsearch_tree. h and name the copy FHlazySearchTree. h. Work on the latter file
for this assignment. Keep the names of the classes the
same: FHs_treeNode and FHsearch_tree. This way a client that works for the old "non-lazy"
trees will still work for the new ones without modification.
1. Add a bool deleted member to FHs_treeNode. Adjust this class to accommodate this
member.
2. Add a new int mSizeHard member to the FHsearch_tree class which tracks the number
of "hard" nodes in it, i. e., both deleted and undeleted. Meanwhile, mSize is still there
and will only reflect the number of undeleted nodes. Normally, the client will not need to
know about mSizeHard, but we want it for debugging purposes. Give it an
accessor, sizeHard(), so the client can test the class by displaying both the soft size (the
number the client normally wants) and the hard size.
3. Revise remove() (the private/recursive version) to implement lazy deletion.
4. Adjust insert() and any other methods that might need revision to work with this new
deletion technique. (The only exceptions to this is the height-related members and
methods which are only there for the derived class AVL tree. You can ignore any heightrelated code you find in the .h file.) (Also, note that when you insert() a new node you will
be inserting as if the deleted nodes were still there. For example, assume a sub tree, root
= 4, lchild = 1, rchild = 6. 4 is deleted. Insert 5. You could approach this by replacing "4"
with "5", but that's not what you should do. You should insert the 5 as if the 4 were still
there and make it a lchild of 6.)
5. Add a public/private pair, void collectGarbage() (the private method is the recursive
counterpart of the public one). This allows the client to truly remove all deleted (stale)
nodes. Don't do this by creating a new tree and inserting data into it, but by traversing
the tree and doing a hard remove on each deleted node. This will require that you have
a private removeHard() utility that works very much like our old remove() method.
6. findMin() and findMax() should return the min or max of the undeleted nodes. In other
words, they should not consider deleted nodes. This means you'll need an additional
function, findMinHard(), which finds the actual min, even if deleted, for use by
removeHard().
7. Test your code thoroughly. Documentation? No need for documentation in functions that you just modified. Just write
function comments for the functions that you wrote completely: the two garbage collection
functions, sizeHard(), findMinHard(), and remove_hard().

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 12:30, kayleigh2037
What characteristic of long period comets suggest they come directly from the oort cloud?
Answers: 2
image
Computers and Technology, 22.06.2019 13:10, LuckyCharms988
Calculating the "total price" of an item is tedious, so implement a get_item_cost method that just returns the quantity times the price for an item. by the way, the technical term for this kind of instance method is an accessor method, but you'll hear developers calling them getters because they always start with "get" and they get some value from instance attributes. in order to make the items sortable by their total total price, we need to customize our class. search the lectures slides for "magic" to see how to do this. see section 9.8 for an additional reference. the receipt class: this will be the class that defines our receipt type. obviously, a receipt will consist of the items on the receipt. this is called the composition design pattern. and it is very powerful. instance attributes: customer_name : it is very important to always know everything you can about your customers for "analytics", so you will keep track of a string customer name in objects of type receipt. date : the legal team has required that you keep track of the dates that purchases happen for "legal reasons", so you will also keep track of the string date in objects of type receipt. cart_items : this will be a list of the items in the cart and hence end up on the receipt. methods: 1. create a default constructor that can take a customer name as an argument, but if it gets no customer name, it will just put "real human" for the customer_name attribute. it should also accept a date argument, but will just use the value "today" for the date instance attribute if no date is given. the parameters should be named the same as the instance attributes to keep things simple. 2. add_item : self-descriptive. takes a parameter which we hope beyond hope is of type itemtopurchase and adds it to the cart_items. returns none. 3. print_receipt : takes a single parameter isevil, with default value true. returns a total cost of all the items on the receipt (remember to factor in the quantity). prints the receipt based on the following specification: for example, if isevil is true, and customer_name and date are the default values: welcome to evilmart, real human today have an evil day! otherwise, it should print: welcome to goodgo, real human today have an good day! then the receipt should be printed in sorted order like we discussed earlier, but whether or not it starts with the highest cost (think reverse), depends on the value of isevil. if it is evil, then the lowest cost items should print first, but if it is good, then it will print the highest cost items first. (cost meaning price*quantity). remember to return the total cost regardless! your main() function: the main flow of control of your program should go in a main() function or the program will fail all the unit tests. get the name of the customer with the prompt: enter customer name: get the date with the prompt: enter today's date then, ask the question: are you evil? your program should consider the following as true: yeah yup let's face it: yes hint: what do these strings all have in common? your program should consider all the following as false: no nah perhaps but i'm leaning no (just be glad you don't have to handle "yeah no.") okay enough horsing around. (get it? aggies? ! horsing! ) next, in the main() function, you will have to create a receipt object and start adding things into it using an input-while loop. the loop will prompt the user for the item name exactly as in the previous zylab (9.11). but unlike the previous zylab, the loop will terminate only if an empty string is entered for the item name. then, the price and the quantity will be prompted for exactly as in the previous zylab. create the itemtopurchase objects in the same manner as the previous zylab, but don't forget to add them to the receipt using your add_item instance method. then, the items on the receipt should be printed with the same formatting as in the previous zylab, of course with either "good" or "evil" ordering. however, on the last line, the total should be printed as follows: where 10 is replaced by the actual total. sample run here is what a sample run of the final program should look like: enter customer name: nate enter today's date: 12/20/2019 are you evil? bwahahahaha yes enter the item name: bottled student tears enter the item price: 2 enter the item quantity: 299 enter the item name: salt enter the item price: 2 enter the item quantity: 1 enter the item name: welcome to evilmart, nate 12/20/2019 have an evil day! salt 1 @ $2 = $2 bottled student tears 299 @ $2 = $598 total: $600
Answers: 1
image
Computers and Technology, 22.06.2019 17:40, pnhandley01
Consider the simple 3-station assembly line illustrated below, where the 2 machines at station 1 are parallel, i. e., the product only needs to go through one of the 2 machines before proceeding to station 2.what is the throughput time of this process?
Answers: 2
image
Computers and Technology, 23.06.2019 01:30, shelley3135
For a typical middle-income family, what is the estimated cost of raising a child to the age of 18? $145,500 $245,340 $304,340 $455,500
Answers: 2
You know the right answer?
This will be your first foray into an actual ADT implementation. It is not a toy program, but the

Questions in other subjects:

Konu
World Languages, 23.09.2019 00:30
Konu
Mathematics, 23.09.2019 00:30