bool QgsComposerNodesItem::removeNode( const int index ) { bool rc = _removeNode( index ); if ( rc ) updateSceneRect(); return rc; }
/*----------------------------------------------------------------------------*/ struct Node *_removeNode(struct Node *cur, TYPE val) { if(compare(cur->val, val) == 0) { cur->val = _leftMost(cur->right); _removeLeftMost(cur->right); }else if(compare(cur->val, val) == -1) { _removeNode(cur->left, val); }else if(compare(cur->val, val) == 1) { _removeNode(cur->right, val); } return cur; }
void _moveNodeAfter(Node* n, Node* after){ //first plug gap in old position _removeNode(n); _insertNodeAfter(n,after); }
/* function to remove a value from the binary search tree param: tree the binary search tree val the value to be removed from the tree pre: tree is not null val is not null val is in the tree pose: tree size is reduced by 1 */ void removeBSTree(struct BSTree *tree, TYPE val) { if (containsBSTree(tree, val)) { tree->root = _removeNode(tree->root, val); tree->cnt--; } }
/*----------------------------------------------------------------------------*/ struct Node *_removeNode(struct Node *cur, TYPE val){ assert(cur != 0); assert(val != 0 && val != NULL); if(compare(cur->val, val) == 0){ //found it if(cur->right == 0){ struct Node *temp = cur->left; free(cur); return temp; } cur->val = _leftMost(cur->right); cur->right = _removeLeftMost(cur->right); } else if(compare(cur->val, val) > 0){ //val is less than cur->val. Go right. cur->left = _removeNode(cur->left, val); } else { //val is greater than cur->val. Go right. cur->right = _removeNode(cur->right, val); } return cur; }
struct Node* _removeNode(struct Node *cur, TYPE val) { if(compare(val, cur->val) == 0){ if(cur->right == NULL){ return cur->left; } else{ cur->val = _leftMost(cur->right); cur->right = _removeLeftMost(cur->right); } } else if(compare(val, cur->val) == 1){ cur->left = _removeNode(cur->left, val); } else{ cur->right = _removeNode(cur->right, val); } return cur; }
/*----------------------------------------------------------------------------*/ struct Node *_removeNode(struct BSTree tree, struct Node *cur, TYPE val) { if ((cur != NULL) && (val != NULL)) { if (containsBSTree(&tree, val)) { struct Node * tmp = NULL; //Base Case if (compare(val, cur->val) == 0) { //If the value is found //If the node has 2 children if ((cur->left != NULL) && (cur->right != NULL)) { tmp = cur; tmp->val = _leftMost(cur->right); cur->right = _removeLeftMost(cur->right); } //If the node has less than 2 children: else { tmp = cur; if (cur->left == NULL) return cur->right; else if (cur->right == NULL) return cur->left; free(tmp); } } else if (compare(val, cur->val) == -1) cur->left = _removeNode(tree, cur->left, val); else if (compare(val, cur->val) == 1) cur->right = _removeNode(tree, cur->right, val); return cur; } else printf("Error: node with specified not inside BST, cannot remove\n"); } else errorEndProg(); }
void testRemoveNode() { struct BSTree *tree = buildBSTTree(); struct Node *cur; struct data myData1; struct data myData2; struct data myData3; struct data myData4; myData1.number = 50; myData1.name = "rooty"; myData2.number = 13; myData2.name = "lefty"; myData3.number = 110; myData3.name = "righty"; myData4.number = 10; myData4.name = "lefty of lefty"; _removeNode(tree->root, &myData4); if (compare(tree->root->val, &myData1) == 0 && tree->root->left->left == NULL) printf("_removeNode(): PASS remove left of left of root 1st try\n"); else printf("_removeNode(): FAIL remove left of left of root 1st try\n"); _removeNode(tree->root, &myData3); if (compare(tree->root->val, &myData1) == 0 && tree->root->right == NULL) printf("_removeNode(): PASS remove right of root 2st try\n"); else printf("_removeNode(): FAIL remove right of root 2st try\n"); _removeNode(tree->root, &myData2); if (compare(tree->root->val, &myData1) == 0 && tree->root->left == 0) printf("_removeNode(): PASS remove left of root 3st try\n"); else printf("_removeNode(): FAIL remove left of root 3st try\n"); cur = _removeNode(tree->root, &myData1); if (cur == NULL) printf("_removeNode(): PASS remove root 4st try\n"); else printf("_removeNode(): FAIL remove root 4st try\n"); }
/*----------------------------------------------------------------------------*/ struct Node *_removeNode(struct Node *cur, TYPE val) { if(compare(cur->val, val) == 0){ //Base Case if(cur->right == 0) return cur->left; else{ /* Copy lowest child to current */ cur->val = _leftMost(cur->right); /* Set right child to subtree with lowest child removed */ cur->right = _removeLeftMost(cur->right); } } else if(compare(val, cur->val) == -1) cur->left = _removeNode(cur->left, val); //Less than == left else cur->right = _removeNode(cur->right, val); //Greater than == right return cur; }
struct Node *_removeNode(struct Node *cur, TYPE val) { assert(cur != 0); assert(val != 0); if(compare(val, cur->val) == 0) { if(cur->right == 0) return cur->left; else { cur->val = _leftMost(cur->right); cur->right = _removeLeftMost(cur->right); } } else if(compare(val, cur->val) == -1) cur->left = _removeNode(cur->left, val); else cur->right = _removeNode(cur->right, val); return cur; }
/*----------------------------------------------------------------------------*/ struct Node *_removeNode(struct Node *cur, TYPE val) { /*write this*/ assert(cur != 0); assert(val != 0 && val != NULL); if(compare(val, cur->val) == 0){ if(cur->right == NULL){ return cur->left; } else{ cur->val = _leftMost(cur->right); cur->right = _removeLeftMost(cur->right); } } else if(compare(val, cur->val) == 1){ cur->left = _removeNode(cur->left, val); } else{ cur->right = _removeNode(cur->right, val); } return cur; }
/* recursive helper function to remove a node from the tree. this function does not decrease tree->cnt. HINT: You have to use the compare() function to compare values. param: cur the current node val the value to be removed from the tree pre: val is in the tree cur is not null val is not null */ struct Node *_removeNode(struct Node *cur, TYPE val) { /* Assert pre-condtions */ assert(val != NULL && cur != NULL); if(!containsBSTree(cur, val)) { printf("ERROR:\tdata not located in tree, aborting...\n"); return cur; } struct Node *tmp; /* Remove value if it is found */ if(compare(cur->val, val) == 0) { if(cur->right == NULL) { tmp = cur->left; free(cur); printf("node deleted\n"); return tmp; } else { /* When a right node exists below a node to be removed */ tmp = _leftMost(cur->right); cur->val = tmp->val; cur->right = _removeLeftMost(cur->right); } } else { if(compare(cur->val, val) == 1) cur->left = _removeNode(cur->left, val); else cur->right = _removeNode(cur->right, val); } return cur; }
/*----------------------------------------------------------------------------*/ struct Node *_removeNode(struct Node *cur, TYPE val) { assert(cur != NULL && val != NULL); int cmpVal = compare(cur->val, val); //node value and test value are equal if(cmpVal == 0) { if(cur->right == NULL) return cur->left; else { cur->val = _leftMost(cur->right); cur->right = _removeLeftMost(cur->right); } } //node value is greater than test value else if(cmpVal == 1) cur->left = _removeNode(cur->left, val); else cur->right = _removeNode(cur->right, val); return cur; }
struct AVLNode *_removeNode(struct AVLNode *cur, void * val, comparator compare) { struct AVLNode *temp; if((*compare)(val, cur->val) == 0) { if(cur->rght != 0) { cur->val = _leftMost(cur->rght); cur->rght =_removeLeftmost(cur->rght); /* return _balance(cur);*/ /* could remove this since there's a return at the end*/ } else { temp = cur->left; free(cur); return temp; } } else if((*compare)(val, cur->val) < 0) cur->left = _removeNode(cur->left, val, compare); else cur->rght = _removeNode(cur->rght, val, compare); return _balance(cur); }
int List_chop(LinkedList* list) { if(list == NULL) { return(LIST_ERR_NULL_ARG); } if(list->_lastNode == NULL) { return(LIST_EMPTY); } struct _ListNode* newLastNode = list->_lastNode->prev; if(list->_curNode == list->_lastNode) { list->_curNode = newLastNode; // Will be null if firstNode was the last node. } if(list->_firstNode == list->_lastNode) { list->_firstNode = newLastNode; // Will be null if firstNode was the last node. } list->_elementDestructor(list->_lastNode->data); _removeNode(list->_lastNode); list->_lastNode = newLastNode; // You guessed it; will be null if firstNode was last node. return(LIST_FUNC_SUCCESS); }
int List_iteratorRemove(LinkedList* list) { if(list == NULL) { return(LIST_ERR_NULL_ARG); } if(list->_curNode == NULL) { return(LIST_EMPTY); } if(list->_curNode == list->_firstNode) { return(List_behead(list) ); } else if(list->_curNode == list->_lastNode) { return(List_chop(list) ); } else { struct _ListNode* newCurNode = list->_curNode->next; if(newCurNode == NULL) { newCurNode = list->_curNode->prev; } list->_elementDestructor(list->_curNode->data); _removeNode(list->_curNode); list->_curNode = newCurNode; } return(LIST_FUNC_SUCCESS); }
void removeAVLTree(struct AVLTree *tree, void * val, comparator compare) { if (containsAVLTree(tree, val, compare)) { tree->root = _removeNode(tree->root, val, compare); tree->cnt--; } }
/* function to remove a value from the binary search tree param: tree the binary search tree val the value to be removed from the tree pre: tree is not null val is not null val is in the tree pose: tree size is reduced by 1 */ void removeBSTree(struct BSTree *tree, TYPE val) { _removeNode(tree->root, val); tree->cnt--; }