Advertisement
Nairo05

Untitled

Jul 6th, 2022
794
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct tnode *deletenode(struct tnode *p, int i) {
  2.     /* end of tree */
  3.     if (p == NULL) {
  4.  
  5.         return NULL;
  6.  
  7.     /* node found, delete */
  8.     } else if (p -> content == i) {
  9.  
  10.         /* case 1: leaf */
  11.         if (p -> left == NULL && p -> right == NULL) {
  12.  
  13.             printf("node is leaf");
  14.  
  15.             free(p);
  16.             return NULL;
  17.  
  18.  
  19.         /* case 2 with children*/
  20.         } else {
  21.  
  22.             struct tnode *q;
  23.             q = addtree(p -> right, p -> left);
  24.             free(p);
  25.             return q;  
  26.  
  27.         }
  28.  
  29.     /* navigate to node */
  30.     } else if (p -> content <= i) {
  31.  
  32.         p -> right = deletenode(p -> right, i);
  33.         return p;
  34.  
  35.     } else {
  36.  
  37.         p -> left = deletenode(p -> left, i);
  38.         return p;
  39.  
  40.     }
  41. }
Advertisement
RAW Paste Data Copied
Advertisement