Question
Note: This is in assmebly language MIPS an dmight be long Write a recursive procedure printtree that prints all the integers currently stored in a
Note: This is in assmebly language MIPS an dmight be long
Write a recursive procedure printtree that prints all the integers currently stored in a binary search tree, in order from smallest to largest. printtree should take as its parameter the address of the root of the tree (or subtree). Note with a simple main program in which the contents of a binary search tree are statically defined under .data. For example, the following directives would statically define a binary search tree with five nodes containing the values 6, 28, 496, 8128, and 33550336, with the value 28 in the root:
rootptr: .word rootnode rootnode: .word lchild .word 28 .word rchild lchild: .word 0 .word 6 .word 0 rchild: .word rchildlchild .word 8128 .word rchildrchild rchildlchild: .word 0 .word 496 .word 0 rchildrchild: .word 0 .word 33550336 .word 0
Your main program should prompt the user to enter 0 (for insert), 1 (for delete smallest), 2 (general delete), or any other integer for termination. If the value 0 is entered, your program should prompt the user to enter an integer, and then should store that integer in a binary search tree. If the value 1 is entered, your program should delete the smallest integer from the tree. If the value 2 is entered, your program should prompt the user to enter an integer, and then should delete that integer (if present) from the tree.
Been stuck for hours now. I was given default procedures
# procedure free returns a node to the free list # procedure arguments as follows: $a0 address of word containing the address of the first node in free list $al- address of node that should be added to free list # Our free list will have a structure like this: # empty word empty word address of next node in free list 4-7 8-11 bytes 0-3 free: lw sto,0(sa0) Load address of first node in free list to to # Store the address of node to be added to free list # set the address linked to the new first node to be the address of previous first node (now it's the second node: sw $t0,8 (al) (remember structure of our free list: empty word empty word address o node in free list sw sw jr $zero, 4 (Sal) $zero, 0 (Sal) Sra # clear the values in the node we're freeing # clear the values in the node we're freeing RETURN FROM WHENCE YOU CAME! # procedure free returns a node to the free list # procedure arguments as follows: $a0 address of word containing the address of the first node in free list $al- address of node that should be added to free list # Our free list will have a structure like this: # empty word empty word address of next node in free list 4-7 8-11 bytes 0-3 free: lw sto,0(sa0) Load address of first node in free list to to # Store the address of node to be added to free list # set the address linked to the new first node to be the address of previous first node (now it's the second node: sw $t0,8 (al) (remember structure of our free list: empty word empty word address o node in free list sw sw jr $zero, 4 (Sal) $zero, 0 (Sal) Sra # clear the values in the node we're freeing # clear the values in the node we're freeing RETURN FROM WHENCE YOU CAMEStep 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