Xóa node mang giá trị là SNT trong cây nhị phân tìm kiếm?

Em code như thế này. Sao không thể xóa được

void ThayThe(NodeInt *&p,NodeInt *&t)
{
	if(t->Left!=NULL)
	{
		ThayThe(p,t->Left);
	}
	else
	{
		p->Key=t->Key;
		p=t;
		t=t->Right;
	}
}
void DelNode(NodeInt *&Root,int x)
{
	if(Root!=NULL)
	{
		if(Root->Key > x) DelNode(Root->Left,x);  //Duyen sang trai
		else if(Root->Key <x) DelNode(Root->Right,x);  //Duyen sang phai
		else  //Node da tim thay
		{
			NodeInt *p=Root; //Giu lai gia tri cua Node Root;
			if(Root->Left==NULL ) Root=Root->Right;
			else
			{
				if(Root->Right==NULL) Root=Root->Left;
				else ThayThe(p,Root->Right);
			}
			free(p);
		}
	}
	else
	{
	    printf("\nNode khong duoc tim thay!");
	}
}
bool KiemTraSNT(int n)
{
	if(n<2) return false;
	
		for(int i=2;i<=n/2;i++)
		{
			if(n%i==0) return false;
		}
		return true;
	
}
void DelSNT(NodeInt *&Root)
{

	if(Root==NULL) return ;
	else
	{
		if(KiemTraSNT(Root->Key)==true)
		{
			DelNode(Root,Root->Key);
		}
		DelSNT(Root->Left);
		DelSNT(Root->Right);
		
	}
	
}

Không có code đầy đủ nên không debug dc. mình nghĩ hàm Thaythe là xóa node nhỏ nhất trong cây chứ không phải là xóa node x

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?