mercredi 15 avril 2020

unordered_set(Hashmap) to store trees

I was thinking to store trees in an unordered set in order to pick the unique trees from a collection of trees. If my tree node has representation like described below, how to come up with the hash function for that ?

struct node {
      int val;
      node *left;
      node *right; 
};

Edit: By similar tree, I mean that they have the same values in all the respective nodes. So, compare function will be using the actual trees to compare rather than memory address of root.

Aucun commentaire:

Enregistrer un commentaire