avlNode_t* avl_insert_equal(avlTree_t *tree, int_t data) { avlNode_t *p = NULL, *curr = NULL, *new_node = NULL; AR_ASSERT(tree != NULL); if(tree->count == 0) { AR_ASSERT(tree->root == NULL && tree->left_most == NULL && tree->right_most == NULL); tree->root = tree->left_most = tree->right_most = __create_node(data); tree->count++; return tree->root; } curr = tree->root; while(curr) { p = curr; if(data < curr->data) { curr = curr->child[AVL_LEFT]; }else { curr = curr->child[AVL_RIGHT]; } } new_node = __create_node(data); if(data < p->data) { p->child[AVL_LEFT] = new_node; }else { p->child[AVL_RIGHT] = new_node; } new_node->parent = p; if(p == tree->left_most && data < p->data)tree->left_most = new_node; if(p == tree->right_most && data >= p->data)tree->right_most = new_node; tree->count++; __fixup(p, &tree->root, new_node == p->child[AVL_LEFT] ? -1 : 1, AVL_INSERT); return new_node; }
arStatus_t Parser_InsertToConfigList(lalrConfigList_t *lst, lalrConfig_t *cfg) { lalrConfigNode_t *node; AR_ASSERT(lst != NULL && cfg != NULL); /*node = AR_NEW0(lalrConfigNode_t);*/ node = __create_node(); if(node == NULL) { return AR_E_NOMEM; } node->config = cfg; node->next = NULL; if(lst->head == NULL) { AR_ASSERT(lst->count == 0); AR_ASSERT(lst->tail == NULL); lst->head = lst->tail = node; }else { lst->tail->next = node; lst->tail = node; } lst->count++; return AR_S_YES; }
/* list_insert(): ------------- Inserts and element in the list lst : pointer to list structure element : data element to be inserted in the list. Returns : -1 if memory allocation error 0 on success */ int list_insert(list_t *lst, void *element) { NODEptr new_node; if ( __create_node( element, &new_node ) == 0 ) { if ( lst->count == 0 ) { lst->head = new_node; } else { NODEptr next = lst->head; lst->head = new_node; lst->head->next = next; next->prev = lst->head; } ++( lst->count ); return 0; } return -1; }