Hmph, so I got this assignment to do, and one of the major hurdles I have is to implement operator overloading on some data structures we made. Basically a lot of my other operators depend on being able to subscript with brackets on these data structures, so that they can be accessed like an array[indx].
But the tree was built as a linked tree, so it seems kinda tricky to access it with subscripts/indices.
Element [0] would access the smallest value in the binary tree. So, given the basic in-order recursive traversal of
if(hasLeft()) then visitLeft()
access node's value
if(hasRight()) then visitRight()
Is this what I would use? But I guess the access part is the problem. I thought I would increment a counter at that point, and check if that counter is equal to the subscript, but it doesn't work like I need it to. Basically, going all the way left would be element zero, but after that I don't know how to find element 1, and so on.
Anyone got any ideas or hints for me?
But the tree was built as a linked tree, so it seems kinda tricky to access it with subscripts/indices.
Element [0] would access the smallest value in the binary tree. So, given the basic in-order recursive traversal of
if(hasLeft()) then visitLeft()
access node's value
if(hasRight()) then visitRight()
Is this what I would use? But I guess the access part is the problem. I thought I would increment a counter at that point, and check if that counter is equal to the subscript, but it doesn't work like I need it to. Basically, going all the way left would be element zero, but after that I don't know how to find element 1, and so on.
Anyone got any ideas or hints for me?