Hi everyone.
I have a problem related to program a binary search tree in SV.
I have done the insertion ,deleting part but have faced some problem related to traversing part.
Please any one know the code to traverse the binary search tree ,tell me.
task insert(A root,int i);
if(temp[i].j<root.j)
begin
if(root.bl==null)
begin
root.bl=temp[i];
q[temp[i].j]=temp[temp[i].j];
$display("insert left j = %d now root is %0d",temp[i].j,root.j);
//i++;
end
else
$display("in left %d and %d",root.j,temp[i].j);
insert(root.bl,i);
end
else if(temp[i].j>root.j)
begin
if(root.br==null)
begin
root.br=temp[i];
q[temp[i].j]=temp[temp[i].j];
$display("insert right j = %d now root is %0d",temp[i].j,root.j);
//i++;
end
else
$display("in right %d and %d",root.j,temp[i].j);
insert(root.br,i);
$display("%d and %d",root.j,temp[i].j);
end
else if(temp[i].j==root.j)
begin
$display("cant insert the same element %d",temp[i].j);
end
endtask:insert