MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / _is_balanced

Function _is_balanced

examples/test/avl.c:79–105  ·  view source on GitHub ↗

return height of current varea */

Source from the content-addressed store, hash-verified

77
78/* return height of current varea */
79static int _is_balanced(rt_varea_t varea)
80{
81 if (!varea)
82 {
83 return 1;
84 }
85
86 rt_varea_t lchild = VAREA_ENTRY(varea->node.node.avl_left);
87 rt_varea_t rchild = VAREA_ENTRY(varea->node.node.avl_right);
88 int lbal = _is_balanced(lchild);
89 int rbal = _is_balanced(rchild);
90
91 if (lbal && rbal)
92 {
93 int diff = lbal - rbal;
94 if (diff > 1 || diff < -1)
95 {
96 printf("lbal %d, rbal %d\n", lbal, rbal);
97 return 0;
98 }
99 else
100 {
101 int height = lbal > rbal ? lbal : rbal;
102 return height + 1;
103 }
104 }
105}
106
107/* add bst assertion */
108static int _check_asc_before(rt_varea_t varea, void *arg)

Callers 2

_check_bst_beforeFunction · 0.85
_check_bst_afterFunction · 0.85

Calls 1

printfFunction · 0.50

Tested by

no test coverage detected