Page 183 - ARM 64 Bit Assembly Language
P. 183
170 Chapter 6
57 {
58 cmp = strcmp(word,root->word);
59 if(cmp < 0)
60 root = wln_lookup(root->left,word);
61 else
62 if(cmp>0)
63 root = wln_lookup(root->right,word);
64 }
65 return root;
66 }
67
68 /**********************************************************/
69 /* wln_height finds the height of a node and returns */
70 /* zero if the pointer is NULL. */
71 int wln_height(wordlistnode *node)
72 {
73 if(node == NULL)
74 return 0;
75 return node->height;
76 }
77
78 /**********************************************************/
79 /* wln_balance finds the balance factor of a node and */
80 /* returns zero if the pointer is NULL. */
81 int wln_balance(wordlistnode *node)
82 {
83 if (node == NULL)
84 return 0;
85 return wln_height(node->left) - wln_height(node->right);
86 }
87
88 /**********************************************************/
89 /* wln_rotate_left rotates counterclockwise */
90 wordlistnode* wln_rotate_left(wordlistnode* rt)
91 {
92 wordlistnode* nrt = rt->right;
93 rt->right = nrt->left;
94 nrt->left = rt;
95 rt->height =
96 MAX(wln_height(rt->left),wln_height(rt->right)) + 1;
97 nrt->height =
98 MAX(wln_height(nrt->left),wln_height(nrt->right)) + 1;
99 return nrt;
100 }
101
102 /**********************************************************/
103 /* wln_rotate_left rotates clockwise */
104 wordlistnode* wln_rotate_right(wordlistnode* rt)
105 {