简体   繁体   English

C数据结构-存储二进制树的表示形式

[英]C data structures - storing a representation of a binary tree

I'm working on a project for an embedded processor where I have some data which is created at runtime, and pointers to this data need to be arranged into several binary tree-like data structures for use by the program. 我正在一个嵌入式处理器的项目中,在该项目中我有一些在运行时创建的数据,并且需要将指向该数据的指针安排到几种二进制树状数据结构中,以供程序使用。

These structures will be fixed for the duration of the program, however, I would like the option at compile time to be able to quickly change how the trees used are structured. 这些结构将在程序执行期间固定不变,但是,我希望在编译时可以快速更改所用树的结构方式。 Something hopefully more elegant and easily re configurable than say, a function or macro for every tree involved that repeatedly calls the "AddNode" function in the proper order for each underlying data element and node of the tree. 比起每个涉及的树,希望有一种更优雅,更容易重新配置的功能,它可以针对树的每个基础数据元素和节点以正确的顺序重复调用“ AddNode”函数。 Thanks for any suggestions! 感谢您的任何建议!

How about using the M4 preprocessor to implement a high-level pseudo-language to generate the C code required to build trees? 使用M4预处理器实现高级伪语言生成生成树所需的C代码怎么样? Your code may have a function called, for instance, initTrees() whose body would be autogenerated by M4 from a file whose content would be a description of the desired tree structure. 您的代码可能具有一个名为initTrees()的函数,该函数的主体将由M4从文件中自动生成,该文件的内容将描述所需的树结构。 The overall process would be as follows: 整个过程如下:

sample.c.m4 ---> [M4] ---> sample.c ---> [C compiler] ---> Binary file sample.c.m4 ---> [M4] ---> sample.c ---> [C编译器] --->二进制文件

http://www.gnu.org/software/m4/ http://www.gnu.org/software/m4/

http://en.wikipedia.org/wiki/M4_(computer_language ) http://en.wikipedia.org/wiki/M4_(computer_language

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM