Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. typedef struct data {
  2.     int average;
  3. } Data;
  4.  
  5. typedef struct node {
  6.     Dani dani;
  7.  
  8.     struct node* pLeft;
  9.     struct node* pRight;
  10. } Node;
  11.  
  12. Node* pRoot;
  13.  
  14. void vydalennjaLystkiv(Node* pNode, Node* pParent, int which) {
  15.     if(!pNode) {
  16.         return;
  17.     }
  18.  
  19.     int flag = 0;
  20.  
  21.     if(!pNode->left && !pNode->right) {
  22.         flag = 1;
  23.  
  24.         if(which == 1) {
  25.             pParent->pLeft = NULL;
  26.         }
  27.         else {
  28.             pParent->pRight = NULL;
  29.         }
  30.  
  31.         free(pNode);
  32.     }
  33.  
  34.     if(!flag) {
  35.         vydalennjaVuzliv(pNode->pLeft, pNode, 1);
  36.         vydalennjaVuzliv(pNode->pRight, pNode, 2);
  37.     }
  38. }
  39.  
  40. void kstVuzliv(Node* pNode, int LIM, Node** ppNodes, int* index) {
  41.     if(!pNode) {
  42.         return;
  43.     }
  44.  
  45.     if(pNode->dani.average > LIM) {
  46.         ppNodes[*index] = pNode;
  47.         (*index)++;
  48.     }
  49.  
  50.     kstVuzliv(pNode->pLeft, LIM, kstVuzliv, index);
  51.     kstVuzliv(pNode->pRight, LIM, kstVuzliv, index);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement