so each previous value of list is returned (popped off stack) until the initial list is returned, which is just copy of the original root pointer from main, right? But if this is the case which makes sense, then why is it that when I output the fcn which returns an address, it is a different address. B/c if the top level
list is returned, then it wouldn't matter for as many reassignments I make.
1 2 3 4
|
root = r_bt_insert(root, 1);
cout << root << endl;//some address
root = r_bt_insert(root, 23);
cout << r_bt_insert(root, 23) << endl;//different address so shouldn't second reassignment of root point to this new address?
|
So in line 4 in the code snippet, it is a DIFFERENT address than in line 2, why? Since initially root points to NULL, so I assign it to the function call, which now makes root point to address of the new node 1, BUT if I reassign root for each new node I insert with the statements:
root = r_bt_insert(root, 23) etc
then I would expect the same address, the initial address of
list, so the COPY of original root's address being returned so the code snippet above SHOULD output the SAME addresses, but there different, that's why I'm lost.
I tinkered around and found out that if I'm inserting and change to:
return newNode
instead of
return list
, then the reassignment does indeed update the root pointe in main to point to this new node which renders the initial node unreachable, but still is different addressees outputted doesn't make sense as explained in above paragraph.
And actually just by changing in insert process from
return list;
to
return newNode;
, I noticed in main
root->data
updates to the new node, so I don't have to reassign w/:
root = r_bt_insert(root, 23);
I hope I make sense...