trees

i am trying to write down a recursive code so that all the left and right pointers of all the leaves are set to point to a special node "sentinel"

1
2
3
4
5
6
7
8
9
10
11
12
void sentinelAssign(list root,list *sentinel)
{
    if(root==NULL)
    {
        root->left=(*sentinel);
    }
    while(root!=NULL)
    {
        sentinelAssign(root->left);
        sentinelAssign(root->right);
    }
}

i know its not correct.plz help!
1
2
3
4
5
6
if(root!=NULL) {
    sentinelAssign(root->left);
    sentinelAssign(root->right);
} else { 
    root = *sentiel;
}
In your original code you tried to access left member of null pointer (line 5)
And had a infinite loop, as root does not changes in it.

I suppose this is the code for a tree?
thnku :)
Topic archived. No new replies allowed.