fork download
  1. #include <stdio.h>
  2.  
  3. /*Макросы для сравнения Equal, Lower Than, Greater Than*/
  4. #define CMP_EQ(a, b) ((a) == (b))
  5. #define CMP_LT(a, b) ((a) < (b))
  6. #define CMP_GT(a, b) ((a) > (b))
  7.  
  8. struct node{
  9. int data;
  10. struct node *left;
  11. struct node *right;
  12. struct node *parent;
  13. };
  14.  
  15. /*Процелура в псевдокоде*/
  16. /*
  17. Tree_Search(x, k)
  18. while x != NIL and k != key[x] do
  19. if k < key[x]
  20. then x <- left[x]
  21. else x <- right[x]
  22. return x
  23. */
  24.  
  25. /*Реализация на си*/
  26. struct node * TreeSearch(struct node *root, int k){
  27. while(root != NULL && root->data != k){
  28. if(k < root->data)
  29. root = root->left;
  30. else
  31. root = root->right;
  32. }
  33. return root;
  34. }
  35.  
  36. int main(void) {
  37. // your code goes here
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 2108KB
stdin
Standard input is empty
stdout
Standard output is empty