Binary search tree

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

In reply to dip0:

in c we can do it easyly by rcursion but in SV it give some error.

In reply to dip0:

if you have C Code(API) which do it correctly then go for DPI. For more Read Section 35 of SV LRM.

Also you will find easy Examples here.
http://www.systemverilog.in/direct-programming-interface.php

Its quite easy to call C Task from SV testcase and get the result back to SV.

I know its doesn’t resolve above mentioned System verilog task issue.But might give another way to resolve it. :)

Regards,
Vinay Jain

In reply to Vinay Jain:

THanks. Any solution in SV code please let me know.

In reply to dip0:

It would really help if you would show the declarations of all variables used in your example. I could probably figure it out on my own, but I do not have the time for that. Ideally enough so someone could easily copy/paste it and try to run it themselves. Also, if you are getting an error, please show that error to everyone.

A couple of other tips:

Use functions instead of tasks unless you need the time blocking capabilities of a tasks.
Make sure your recursive function is declared ‘automatic’. If it is inside a class, that is the default, but outside of a class method, the default is static.