Before I head into one-upping my program that renames .docx files that have a '+' in the name (it works in three directories), I figured that the right approach would be tree-implementation. However, I have never taken the class that was recommended to be taken along with second semester computing class, data structures. As a consequence, I have to teach myself the stuff that I would need to know. To do this, I am trying to implement a binary search tree (a project that is ubiquitous amongst novice programmers, I know). I have decided that it should take user input about how many levels there should be total, and then create a binary search tree with that many levels starting with 1 being the leftmost leaf node. (That means that for a tree of x levels, you are looking at a parent node of 2^(x-1), a rightmost leaf node of 2^(x+1)-1 == 2^x+1, and the change j units from the top to be 2^(x-(j+1)). Here is my code so far: its complaints are based on me trying to either declare or directly call the struct's lefttree and righttree)
Yes, I know that the value of a left node of a parent is less than that of the parent and the right node of the parent is greater in value to that of the parent. I thought I have stated as much. (I guess I didn't.) I thought it would be easier to do it with integers between 1 and pow(2,n)+1. And yes, I knew that the ^ was the exclusive OR; it has been a while since I did any serious mathematical manipulation in C++, but thanks for the refresher. I also see you hinting at me needing to use OOP. Probably the best habit. I can also see that you are using a declaration of Node* instead of Node. I should take note and try it again; this way, I can just refer to &Tree to touch the parent object. But, does Tree correspond to left or right? Or is the entire tree either going to be addressed by Tree? If so, how do I address the cases where n < max && n != 0? Clearly, the left and right nodes have to be set, and I can't just use
because that would only refer to the first subnodes!
I could, however, use this with a recursive function that takes tree * a as parameter. My question is this: what would a be? Would it be leftnode, rightnode, or simply a struct pointed to by an instance of tree? This would answer the question as to what the meaning of a->lefttree.element means. (I think it means the element of the lefttree pointed to by a.)
EDIT: Problem solved. Thanks to everyone who posted here and got me started!