Reputation: 198 Stalwart
- Active Members
- Active Posts:
- 1,668 (1.11 per day)
- 13-March 10
- Profile Views:
- Last Active:
- Today, 03:04 PM
- Dream Kudos:
Posts I've Made
Posted 1 Apr 2014So that means i need to be member of dreamincode, stackoverflow, bytes etc etc just to see someone have a similar problem to mine and use solution provided?
Posted 27 Mar 2014Ignore my previous reply. I have stepped through the code with pen and paper and i see that the leftChild is the local pointer. So how do i change the code so that the left child pointer is the actual pointer of roots left child.
Posted 27 Mar 2014Why is it a local variable?
I will break it down and show you my thinking behind it and you can tell me where i am wrong.
Let's imagine the code in main we are executing is:
1) newNode created at memory address: 0xB (inside insert() method)
2) root has been initialized at memory address: 0xA. (inside insert() method)
3)calling insertNode(0xA, 0xB);
6)root is not NULL so we skip this
7)the else if statement executes and we go inside
8) Node* leftChild is pointing to meomry address 0xC (which is NULL for now).
9!) We call insertNode(0xC, 0xB)
10)0xC is NULL so the first if statement executes and we set pointer to point to newNode.
Where am i missing it?
Posted 26 Mar 2014OK. I have tried again from scratch and now when i am inserting the first node it is working. When i try to insert the second node - with value 3 - the Node comes out as NULL.
When calling recursively it is not getting updated. I have tried your suggestion and now i am passing pointer by reference but it still gives errors.
Posted 16 Mar 2014Thanks. I have fixed the code accordingly but now the program exits with an error code.
It seems as if i go 1 Node too far in printing since it prints:
Is my while loop in the printList() method correct?
- Member Title:
- D.I.C Lover
- Age Unknown
- Birthday Unknown
- Click here to e-mail me
darek9576 hasn't added any friends yet.