如果你 #2~#9 全是 MLE
查看原帖
如果你 #2~#9 全是 MLE
761125
Milthm楼主2024/5/3 14:16
void del(int x){
	if(!x)return;
	stk[++top]=x;
	if(ch[x][0])del(ch[x][0]);
	if(ch[x][1])del(ch[x][1]);
}

如果你删除子树是这么写的,再次把点拿出来的时候,相当于把以它为根的子树全拿出来了,然后就炸了,所以正确的写法应该是:

void del(int x){
	if(!x)return;
	stk[++top]=x;
	if(ch[x][0])del(ch[x][0]);
	if(ch[x][1])del(ch[x][1]);
	ch[x][0]=ch[x][1]=0;
}
2024/5/3 14:16
加载中...