the 'best method' depends on what searches you allow.
if you want to search all programmers, for example, that is different from what you stated, which is give the program specific info to locate specific person.
if your design is just 'get one person who matches input (of 1 or more 'keys') the 'best' design is probably some sort of hashed container. Imagine an array, and imagine you can turn your data into an index into that array.
Then when user gives input, you convert to the number, check the array at that slot, if its there (and possibly, check that it matches) they got it right, show them the data, if not, the person didnt exist in the data. No searching involved.
but as I said, you can load up a tree and search it if you like. If the assignment is a tree, you should do a tree :P
I dislike things like trees and if forced to deal with one will usually cram it into a vector on the back end and make it look like a tree.
This allows you to do some stuff behind the scenes a little cleaner than trying to manhandle pointers. Effectively, all you do instead of new / pointer is do a push-back and grab the new index.
Treat index like a pointer, otherwise its the same on the tree side. This is a slightly more advanced approach as you would need to know when to use the tree functions and when to cheat and use the vector functions, which is a lot to go into here. I don't recommend it right now, but as you do the tree work, think to yourself "would this function be easier if I were processing a vector??" and you will start to see for yourself what I mean.
Binary Search Trees (BST) - Insertion and Deletion Explained
Things like "process every item in the data" go from a recursive tree processing algorithm to a simple loop. Sorting it and rebuilding the tree (rebalance algorithm, in tree terminology) becomes efficient and a breeze.
Last edited on