I am really getting confused between using while and if loops
eg: Here's a solution for swapping current element with it's left node in a binary tree:
why can't I replace if (T!=NULL) with while(T!=NULL)?...please give me some suggestion on when to use what....Code:TREE swap_left (TREE T){ element_type tmp; if(T!=NULL){ if(T->left){ tmp = T->element; T->element = T->left->element; T->left->element = tmp; } swap_left(T->right); swap_left(T->left); } return T; }