-1
Я не могу найти правильную логику для удаления узла из двоичного дерева поиска. Удаление узла из BST без использования генераторов
public void delete(int key){
node current=root;
int flag=0;
if(current.data==key){
System.out.println(key+" is deleted");
current.rightchild=null;
current.leftchild=null;
current=null;
}
else{
while(true){
if(current.data>key){
current=current.leftchild;
if(current==null){
flag=1;
break;
}
if(current.data==key){
System.out.println(key+" is deleted");
current.leftchild=null;
current.rightchild=null;
current=null;
break;
}
}
else{
current=current.rightchild;
if(current==null){
flag=1;
break;
}
if(current.data==key){
System.out.println(key+" is deleted");
current.leftchild=null;
current.rightchild=null;
current=null;
break;
}
}
}
}
if(flag==1){`enter code here`
System.out.println(key+" Not Found");
}
}
Это для вашего запроса «логика» для удаления .... его в C++ .... только для того, чтобы быть ясным – Bar
Возможно ли использовать без использования дженериков? –
Да, просто замените предварительные определения типов данных ... – Bar