I have already commented on almost exactly the same code (including the error Wile E Coyote was pointing out). See your previous thread. Segmentation error while creating a tree - yet it seems you have fixed none of the issues but instead added some random code.
Maybe your problem is more fundamental. Can’t you ask a colleague? That’s probably more useful than discussing your code here.