int kthMin(NODEPTR T,int *k){ int x; if(T){ x=kthMin(T->left ,k); if((*k)!=0){ (*k)--; if(*k==0) return(T->key); return(kthMin(T->right,k)); } } return x; }
int kthMin(BinarySearchTree *t, int *k) { if(t == NULL) return INT_MAX; int x = kthMin(t->left, k); if(x != INT_MAX) return x; (*k)--; if(*k == 0) return t->data; return kthMin(t->right, k); }
main() { NODEPTR *tree; int ch;int j=0; //int number; *tree=NULL; while(1){ printline('*'); printf("Enter the choice:-"); printf("\n1.Insert the element\n2.Delete the element\n3.Traversal\n4.call function\n"); scanf("%d",&ch); printline('='); switch(ch){ case 1: insert(tree);break; case 2: // delete();break; case 3: traversal(*tree);break; case 4:printf("\nEnter the no u want to smallest\n"); scanf("%d",&j); printf("\n%d\n",kthMin(*tree,&j));printline('*');break; default: printf("Hi i m default"); break; }/*end of switch*/ }/*end of while*/ }/*end of main*/