Updated pre_order to save leaf nodes in a stacl