123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #include <assert.h>
- #include "private.h"
- int lub_bintree_insert(lub_bintree_t * this, void *clientnode)
- {
- int result = -1;
- lub_bintree_node_t *new;
- lub_bintree_key_t key;
- assert(clientnode);
- if (NULL != clientnode) {
-
- new = lub_bintree_getnode(this, clientnode);
-
- assert(new->left == NULL);
- assert(new->right == NULL);
-
-
- if (NULL == this->root) {
- this->root = new;
- this->root->left = this->root->right = NULL;
- result = 0;
- } else {
- int comp;
-
- this->getkeyFn(clientnode, &key);
-
- this->root = lub_bintree_splay(this, this->root, &key);
-
- comp = lub_bintree_compare(this, this->root, &key);
- if (comp > 0) {
- new->left = this->root->left;
- new->right = this->root;
- this->root->left = NULL;
- result = 0;
- } else if (comp < 0) {
- new->right = this->root->right;
- new->left = this->root;
- this->root->right = NULL;
- result = 0;
- } else {
-
- }
- }
- if (0 == result) {
-
- this->root = new;
- }
- }
-
- return result;
- }
|