Advertisement
Guest User

Untitled

a guest
May 3rd, 2011
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. struct treeNode
  2. {
  3. int data;
  4. struct treeNode *left, *right:
  5. };
  6.  
  7. //This recursive function will find the kth smallest node in a binary search tree
  8. int rank(struct treeNode*ptr, int k)
  9. {
  10. int counter = 0;
  11.  
  12. if(ptr == NULL)
  13. return NULL;
  14.  
  15. while(counter != k)
  16. //In order traversal
  17. rank(ptr->left);
  18. rank(ptr->root);
  19. rank(ptr->right);
  20. counter++;
  21. }
  22.  
  23. return k;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement