fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class node
  5. {
  6. public:
  7. string word;
  8. string mean;
  9. node *left;
  10. node *right;
  11. node *root;
  12. node *root1;
  13.  
  14. node()
  15. {
  16. left = NULL;
  17. right = NULL;
  18. }
  19. void insert();
  20. void insertion(node *, node *);
  21. void remove();
  22. void getdata();
  23. void display();
  24. };
  25. void node :: getdata()
  26. {
  27. cout<<"Enter the keyword: "<<endl;
  28. cin>>root->word;
  29.  
  30. cout<<"Enter its meaning: "<<endl;
  31. cin>>root->mean;
  32.  
  33. root1 = root;
  34. }
  35. void node :: insert()
  36. {
  37. node *temp = new node;
  38.  
  39. cout<<"Enter the keyword: "<<endl;
  40. cin>>temp->word;
  41.  
  42. cout<<"Enter its meaning: "<<endl;
  43. cin>>temp->mean;
  44.  
  45. insertion(root1, temp);
  46. }
  47. void node :: insertion(node *c, node *temp)
  48. {
  49. if(temp->word < c->word && c->left==NULL)
  50. {
  51. c->left = temp;
  52. }
  53. else if(temp->word > c->word && c->right==NULL)
  54. {
  55. c->right = temp;
  56. }
  57. else if(temp->word < c->word && c->left!=NULL)
  58. {
  59. insertion(c->left, temp);
  60. }
  61. else if(temp->word > c->word && c->right!=NULL)
  62. {
  63. insertion(c->right, temp);
  64. }
  65. else
  66. {
  67. cout<<"Error!"<<endl;
  68. }
  69. }
  70.  
  71. int main()
  72. {
  73. node n;
  74.  
  75. n.getdata();
  76. n.insert();
  77. n.insert();
  78. n.insert();
  79.  
  80. return 0;
  81. }
  82.  
Runtime error #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Enter the keyword: 
Enter its meaning: 
Enter the keyword: 
Enter its meaning: