G2A Many GEOs
SHARE
TWEET

Untitled

jaderadeee Mar 30th, 2020 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //DELETE MOVIE HELPER FUNCTIONS
  2.  
  3.  
  4. TreeNode* findHelper(TreeNode* parent, TreeNode* temp) {
  5.   if (parent->titleChar == temp->titleChar) {
  6.     return parent;
  7.   }
  8.   else {
  9.     if (parent->titleChar < temp->titleChar) {
  10.       return findHelper(parent->rightChild, temp);
  11.     }
  12.     if (parent->titleChar > temp->titleChar) {
  13.       return findHelper(parent->leftChild, temp);
  14.     }
  15.   }
  16. }
  17.  
  18. TreeNode* findParent(TreeNode* temp, TreeNode* root) {
  19.   TreeNode* parent = findHelper(root, temp);
  20.   if (parent->rightChild == temp || parent->leftChild == temp) {
  21.     return temp;
  22.   }
  23.   else {
  24.     return NULL;
  25.   }
  26. }
  27.  
  28. TreeNode* returnMaxNode(TreeNode* currNode){
  29.     if(currNode->rightChild == NULL){
  30.         return currNode;
  31.     }
  32.     return returnMaxNode(currNode->rightChild);
  33. }
  34.  
  35. TreeNode* returnMinNode(TreeNode* currNode){
  36.  
  37.     if(currNode->leftChild == NULL){
  38.       return currNode;
  39.     }
  40.     return returnMinNode(currNode->leftChild);
  41. }
  42.  
  43.  
  44. void removeNode(TreeNode* temp, TreeNode* root) {
  45.   if (temp->rightChild == NULL && temp->leftChild == NULL) {
  46.     TreeNode* parent = findParent(temp, root);
  47.     cout << parent->titleChar << endl;
  48.     temp = NULL;
  49.   }
  50.   else if (temp->rightChild == NULL && temp->leftChild != NULL) {
  51.     TreeNode* min = returnMinNode(temp->rightChild);
  52.     temp = min;
  53.     min = NULL;
  54.   }
  55.   else if (temp->rightChild != NULL && temp->leftChild == NULL) {
  56.     TreeNode* max = returnMaxNode(temp->leftChild);
  57.     temp = max;
  58.     max = NULL;
  59.   }
  60.   else {
  61.     TreeNode* max = returnMaxNode(temp->leftChild);
  62.     temp = max;
  63.     max = NULL;
  64.   }
  65. }
  66.  
  67. void MovieTree::deleteMovie(std::string title)
  68. {
  69.   TreeNode* searched = new TreeNode;
  70.   searched = searchNode(title[0], root);
  71.   //if the character has been searched before
  72.   if (searched != NULL) {
  73.     LLMovieNode* curr = searched->head;
  74.     LLMovieNode* prev = curr;
  75.     //while the current node has been searched before
  76.     while (curr != NULL)
  77.     {
  78.       //if it is the correct title and we are at the searched node
  79.       if (curr->title == title && curr == searched->head) {
  80.         //at the end of the LL
  81.         //the last element present
  82.         if (curr->next == NULL) {
  83.           delete curr;
  84.           searched->head = NULL;
  85.           removeNode(searched, root);
  86.         }
  87.         //when there are other elements still in the LL
  88.         else
  89.         {
  90.           searched->head = curr->next;
  91.           delete curr;
  92.         }
  93.       }
  94.       else if (curr->title == title) {
  95.         prev->next = curr->next;
  96.         delete curr;
  97.       }
  98.       //movie not found
  99.       else {
  100.         prev = curr;
  101.         curr = curr->next;
  102.       }
  103.     }
  104.   }
  105. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top