Your naming is messed up.
You have two variables named T
, one at global scope and the other as parameter to insert
. Therefore the assignment T=z;
in insert
does not actually work on the global variable T
but on the parameter and hence has no side-effect outside the function.
As a general rule, try to avoid single-letter variable names like T
, z
and x
. They make your code hard to read and can easily hide mistakes like this one. Also, avoid doing non-localized updates from within functions. Updating global variables from functions is just asking for trouble like this. A better approach would be to have insert
return a pointer to the new top-level node instead.