mardi 23 mai 2017

Correct way to store a BST in a map using a Date object as the key

So I want to create a map structure that uses a Date object as the key to a Tree of values.

I have tried a couple methods however both have not worked.

method 1 map>:

map<Date, BST<float>> dateMap;
dateMap.insert(std::pair<Date, BST<float>>(dateObjt, BST))

The problem i encountered with this method is when i do a traversal that to print out the values it is spitting out garbage. And when i run the debugger it segmentation error.

method 2 map*>:

map<Date, BST<float>*> dateMap;
dateMap.insert(std::pair<Date, BST<float>*>(dateObjt, &BST))

in this case when I use the traversal when there is only one item stored in the map it is able to traverse the tree, however when second data is entered it traverses the tree in a infinite loop then is killed with a segmentation error.

What would be the best method to map a tree to a Date key allowing for traversal?

Aucun commentaire:

Enregistrer un commentaire