creating a copy of BST

Mar 18, 2014 at 8:01am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void copy(node *& dest, node * root)
{
  if(!root)
    {
      dest = NULL;
      return;
    }
  else
    {
        dest = new node;
        dest -> data = root -> data;
        copy(dest -> left, root -> left);
        copy(dest -> right, root -> right);
    }
 


Above is my code, I'm running a seg fault when I run it in linux. I looks correct to me and everything is in place? Any ideas?

Thanks
Mar 18, 2014 at 9:04am
Aren't you supposed to set the left and right to null somewhere?
Mar 18, 2014 at 4:06pm
The seg fault might not be coming from this code. I don't see anywhere it might be causing seg fault either.

http://coliru.stacked-crooked.com/a/1ac9447244834924
Last edited on Mar 18, 2014 at 4:12pm
Topic archived. No new replies allowed.