| Welcome to UCR CS 14 Klefstad. You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you're already a member please log in to your account to access all of our features: |
| finding parent node | |
|---|---|
| Tweet Topic Started: Feb 21 2014, 07:40 PM (64 Views) | |
| rdinh002 | Feb 21 2014, 07:40 PM Post #1 |
|
I'm working on a function called findParent which returns the parent of a certain node. When implementing in my remove function it gives me a seg fault and I don't understand why I get one. Spoiler: click to toggle
|
![]() |
|
| jdomi008 | Feb 22 2014, 12:05 PM Post #2 |
|
instead of calling find in the remove function then calling findParent, you can just write the exact same code for find inside remove but with a couple added lines to keep track of the parent. |
![]() |
|
| klefstad | Feb 28 2014, 12:06 PM Post #3 |
Administrator
|
Calling another function to find the parent is far too expensive and wasteful wince you've already done the work. If you really need to know, keep the parent pointer (like a previous pointer in a singly linked list) as you traverse. Or better yet, use reference parameter for the TreeNode* parameter, then you can assign into it to modify the pointer passed in. Or have your function return the pointer and at each appropriate point, assign the value returned by the function, like remove, back into the pointer you are removing from. |
![]() |
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| « Previous Topic · Homework 6 · Next Topic » |






12:15 PM Jul 11