how to use Matlab coder to generate C code with a binary tree

2 次查看(过去 30 天)
I just want to generate C code where a binary tree is involved. following is the related code, in which I have a structure named "node", which contains members "left" and "right". I want "left" and "right" can also be a "node" structure.
But I always get errors when generating the C code, saying "the Structures don't match". I understand that I need to make sure the new node assigned to left should have the same structure, but don't know how to realize that.
function node=tree()
% initialize the root node
node.val=1;
node.left=struct();
node.right=struct();
% create a new node and assign to left
nkd.val=2;
nkd.left=struct();
nkd.right=struct();
node.left=nkd;

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink PLC Coder 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by