小编FDF*_*ock的帖子

用C(以及其他命令式语言)打印二叉树

(第一次发布海报,而不是新编程,请耐心等待!)

我对打印格式化二叉树(在CLI环境中)和C实现的高效通用算法感兴趣.这是我为了好玩而编写的一些代码(这是原始版本的简化版本,是支持许多BST操作的大型程序的一部分,但它应该编译得很好):

#include <stdbool.h>    // C99, boolean type support
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define DATATYPE_IS_DOUBLE
#define NDEBUG                      // disable assertions
#include <assert.h>

#define WCHARBUF_LINES          20  // def: 20
#define WCHARBUF_COLMS          800 // def: 80 (using a huge number, like 500, is a good idea,
                                    //          in order to prevent a buffer overflow :)
#define RECOMMENDED_CONS_WIDTH  150
#define RECOMMENDED_CONS_WIDTHQ "150"   // use the same value, quoted

/* Preprocessor directives depending on DATATYPE_IS_* : */
#if …
Run Code Online (Sandbox Code Playgroud)

c language-agnostic binary-tree pretty-print

7
推荐指数
1
解决办法
9075
查看次数

标签 统计

binary-tree ×1

c ×1

language-agnostic ×1

pretty-print ×1