C - deleting n-ary tree nodes -


i have implemented in c m,n,k-game ai. game works fine when have free decision tree throws "access violation reading location" exception.

implementation of decision tree structure:

typedef struct decision_tree_s {     unsigned short **board;     status_t status;     struct decision_tree_s *brother;     struct decision_tree_s *children; } decision_tree_t; 


, implementation of delete_tree function:

void delete_tree(decision_tree_t **tree) {     decision_tree_t *tmp;      if (*tree != null) {         delete_tree((*tree)->children);         delete_tree((*tree)->brother);          free(*tree);         *tree = null;     } } 

you destroying twice children member: first time in for loop, second time after loop.

you might want write loop that:

for (tmp = tree->brother; tmp != null; tmp = tmp->brother) {     delete_tree(tmp); } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -