"I am unable to complete the R code for deleting nodes in a binary search
tree."
What does this mean? What errors did you receive or what did or did not
happen with your current code? With what code was the tree built?
Also, this smells like homework. We do not do homework (or try not to) on
this list.
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, Oct 3, 2017 at 7:28 AM, Karthiko S <karthik.100 at gmail.com>
wrote:
> 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 at 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.
>
[[alternative HTML version deleted]]