Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. ==22345== Invalid read of size 4
  2. ==22345== at 0x8048C3C: insert (in /home/plaidypus/Documents/avltree)
  3. ==22345== by 0x80488B6: main (in /home/plaidypus/Documents/avltree)
  4. ==22345== Address 0x3 is not stack'd, malloc'd or (recently) free'd
  5.  
  6. ==22345== 1 errors in context 2 of 3:
  7. ==22345== Use of uninitialised value of size 4
  8. ==22345== at 0x8048C3C: insert (in /home/plaidypus/Documents/avltree)
  9. ==22345== by 0x80488B6: main (in /home/plaidypus/Documents/avltree)
  10.  
  11. ==22345== 1 errors in context 3 of 3:
  12. ==22345== Conditional jump or move depends on uninitialised value(s)
  13. ==22345== at 0x8048C03: insert (in /home/plaidypus/Documents/avltree)
  14. ==22345== by 0x80488B6: main (in /home/plaidypus/Documents/avltree)
  15.  
  16. void rightRotate(node * y)
  17. {
  18. /* Assign values */
  19. node *x = y->left;
  20. node *subTree = x->right;
  21.  
  22. /* Perform rotation */
  23. x->right = y; /* x is now root */
  24. y->left = subTree;
  25.  
  26. /* Update heights */
  27. y->height = max(height(y->left), height(y->right))+1;
  28. x->height = max(height(x->left), height(x->right))+1;
  29. }
  30.  
  31. void insert(node ** tree, node * item)
  32. {
  33. int balanceNum;
  34.  
  35. /* If no root, item is root */
  36. if(!(*tree)) {
  37. *tree = item;
  38. printf("Root: n");
  39. (*tree)->height = 0;
  40. printNode(*tree);
  41. return;
  42. }
  43.  
  44. if(strcmp(item->key,(*tree)->key) < 0) {
  45. insert(&(*tree)->left, item);
  46. }
  47. else if(strcmp(item->key,(*tree)->key) > 0) {
  48. insert(&(*tree)->right, item);
  49. }
  50. else if(strcmp(item->key,(*tree)->key) == 0) {
  51. (*tree)->frequency++;
  52. }
  53.  
  54. /* Update height of ancestor node */
  55. (*tree)->height = max(height((*tree)->left), height((*tree)->right)) + 1;
  56. printf("%s Height: %dn", (*tree)->key, (*tree)->height);
  57.  
  58. balanceNum = balance(*tree);
  59.  
  60. if(balanceNum > 1 && strcmp(item->key,(*tree)->left->key) < 0) {
  61. printf("Right Rotate! Balance: %d with %sn", balanceNum, item->key);
  62. rightRotate(*tree);
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement