0
void kthlargestele(struct node*a,int h,int *c){
    if(a==NULL||*c>=h){
        return ;


    }
    kthlargestele(a->right,h,&c);
    *c++;
    if(*c==h){
        printf("kth largest element is %d",a->item);
    }
    kthlargestele(a->left,h,&c);
}
void kthlargest(struct node*root,int k){
    int c=0;
    kthlargestele(root,k,&c);
}

The above functions are supposed to print the kth largest element in binary search tree. the inorder of the tree is --17--18--19--20--30--27--35 .However the functions above are not printing anything and I cant figure out why.

Evg
  • 25,259
  • 5
  • 41
  • 83
  • `*c++;` is nonsense. – Lundin May 19 '21 at 12:49
  • If I am not missing something, then you are getting the address of `c` in the line `kthlargestele(a->right,h,&c);`, but `c` is already a pointer inside `kthlargestele()`, although not in `kthlargest()`. Aren't you getting a segfault for accessing those memory addresses? – Ganathor May 19 '21 at 12:51
  • @Lundin (in case it was you who closed the question) I think that the link given as a duplicate may apply to the problem in this question, but is it not exactly a duplicate and I think it should not be marked as that. Can you or anyone point me to the rules of marking something as duplicate? – Ganathor May 19 '21 at 13:05
  • @Ganathor It says right there who closed the question, wasn't me, though I agree with it. It may not address _all_ problems in the question, but at least one of the most obvious. The OP can then read the duplicate, apply the changes suggested and see if it solves the problem. If some other problem remains after fixing it, they can either edit this question here (since it has no answers yet) or post a new one with the changed code. – Lundin May 19 '21 at 13:34

0 Answers0