Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ==22345== Invalid read of size 4
- ==22345== at 0x8048C3C: insert (in /home/plaidypus/Documents/avltree)
- ==22345== by 0x80488B6: main (in /home/plaidypus/Documents/avltree)
- ==22345== Address 0x3 is not stack'd, malloc'd or (recently) free'd
- ==22345== 1 errors in context 2 of 3:
- ==22345== Use of uninitialised value of size 4
- ==22345== at 0x8048C3C: insert (in /home/plaidypus/Documents/avltree)
- ==22345== by 0x80488B6: main (in /home/plaidypus/Documents/avltree)
- ==22345== 1 errors in context 3 of 3:
- ==22345== Conditional jump or move depends on uninitialised value(s)
- ==22345== at 0x8048C03: insert (in /home/plaidypus/Documents/avltree)
- ==22345== by 0x80488B6: main (in /home/plaidypus/Documents/avltree)
- void rightRotate(node * y)
- {
- /* Assign values */
- node *x = y->left;
- node *subTree = x->right;
- /* Perform rotation */
- x->right = y; /* x is now root */
- y->left = subTree;
- /* Update heights */
- y->height = max(height(y->left), height(y->right))+1;
- x->height = max(height(x->left), height(x->right))+1;
- }
- void insert(node ** tree, node * item)
- {
- int balanceNum;
- /* If no root, item is root */
- if(!(*tree)) {
- *tree = item;
- printf("Root: n");
- (*tree)->height = 0;
- printNode(*tree);
- return;
- }
- if(strcmp(item->key,(*tree)->key) < 0) {
- insert(&(*tree)->left, item);
- }
- else if(strcmp(item->key,(*tree)->key) > 0) {
- insert(&(*tree)->right, item);
- }
- else if(strcmp(item->key,(*tree)->key) == 0) {
- (*tree)->frequency++;
- }
- /* Update height of ancestor node */
- (*tree)->height = max(height((*tree)->left), height((*tree)->right)) + 1;
- printf("%s Height: %dn", (*tree)->key, (*tree)->height);
- balanceNum = balance(*tree);
- if(balanceNum > 1 && strcmp(item->key,(*tree)->left->key) < 0) {
- printf("Right Rotate! Balance: %d with %sn", balanceNum, item->key);
- rightRotate(*tree);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement