creating a copy of BST

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
Aren't you supposed to set the left and right to null somewhere?
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
Topic archived. No new replies allowed.