fork download
  1. #include <stdio.h>
  2. #include<stdlib.h>
  3. struct node
  4. {
  5. int data;
  6. struct node *left,*right;
  7. };
  8. int count=0;
  9. void print(struct node*root,int k)
  10. {
  11. if(root!=NULL&&count<=k)
  12. {
  13. print(root->right,k);
  14. count++;
  15. if(count==k)
  16. printf("%d ",root->data);
  17. print(root->left,k);
  18. }
  19. }
  20. struct node* create(struct node*root,int x)
  21. {
  22. struct node*p=(struct node*)malloc(sizeof(struct node));
  23. p->data=x;
  24. p->left=NULL;
  25. p->right=root;
  26. return p;
  27. }
  28. void show(struct node*root)
  29. {
  30. while(root!=NULL)
  31. {
  32. printf("%d ",root->data);
  33. root=root->right;
  34. }
  35. }
  36. int main()
  37. {
  38. // your code goes here
  39. struct node*root=NULL;
  40. root=create(root,5);
  41. root=create(root,6);
  42. root=create(root,7);
  43. //root=create(root,8);
  44. //root=create(root,9);
  45. //show(root);
  46. print(root,1);
  47. }
  48.  
Success #stdin #stdout 0s 4724KB
stdin
Standard input is empty
stdout
5