问题描述
我正在尝试使用 OOP 概念在 System Verilog 中执行二叉树插入和顺序遍历。在创建对象之前,我收到了正在使用该对象的错误消息。请看一下代码,如果有人发现任何错误,请帮助我
class node;
byte data;
node left;
node right;
function new();
this.data = data;
this.left = null;
this.right = null;
endfunction
endclass
class bin_search extends node;
node newNode;
node nd,root,current,parent;
byte in_data;
function new();
super.new();
this.in_data = in_data;
endfunction
function automatic insert(in_data);
newNode.data = nd.data;
if(root.data == null) begin
root = newNode;
return;
end
else begin
current = root;
parent = null;
end
forever begin
parent = current;
if(in_data < current.data) begin
current = current.left;
if(current.left == null) begin
parent.left = newNode;
return;
end
end
else begin
current = current.right;
if(current.right == null) begin
parent.right = newNode;
return;
end
end
end
endfunction
function automatic inorder_traverse(node node_tr);
//using nodes here
endfunction
endclass
module binary;
node NODE;
bin_search bs;
byte ins;
initial begin
NODE = new;
bs = new;
bs.insert(50);
$display("Binary search tree after insertion:");
bs.inorder_traverse(bs.root);
end
endmodule
错误信息: 错误-[NOA] 空对象访问 二进制.sv,28 解除引用深度为 1 的对象在被使用之前被使用 构建/分配。 使用前请确保对象已分配。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)