Dear All,

I am unable to complete the R code for deleting nodes in a binary search
tree.

Have provided the code snippet below for an usecase where the node to be
deleted would have a leftnode and no rightnode. I am stuck up at how to
release the node pertaining to the key value given by the function
call and then
assigning the leftnode in place of the deleted note.

Any help would be appreciated .

    deletenode<-function(node,key)

    {

    if(identical(node,NULL)==TRUE)

    {

    return(node)

    }

    else

    {

    if(key<node$key)

    {

    node$leftnode<-deletenode(node$leftnode,key)

    }

    if(key>node$key)

    {

    node$leftnode<- deletenode(node$rightnode,key)

    }

    if(key==node$key)

    {

      if((identical(node$leftnode,NULL)==TRUE)&&

                      (identical(node$rightnode,NULL)==FALSE))

    {

    temp<-node

    node<-node$rightnode

    remove(temp)

    return(node)

    }



    }

    deletenode(root,key)


Thanks and Regards

karthik

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to