Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct treeNode
- {
- int data;
- struct treeNode *left, *right:
- };
- //This recursive function will find the kth smallest node in a binary search tree
- int rank(struct treeNode*ptr, int k)
- {
- int counter = 0;
- if(ptr == NULL)
- return NULL;
- while(counter != k)
- //In order traversal
- rank(ptr->left);
- rank(ptr->root);
- rank(ptr->right);
- counter++;
- }
- return k;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement