fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. struct school
  9. {
  10. int key;
  11. school *p_right;
  12. school *p_left;
  13. };
  14.  
  15. school *locale(school *NCT, int key)
  16. {
  17. if (key < NCT->key)
  18. {
  19. if (NCT->p_left == NULL)
  20. return NCT;
  21. else
  22. return locale(NCT->p_left, key);
  23. }
  24. else
  25. {
  26. if (NCT->p_right == NULL)
  27. return NCT;
  28. else
  29. return locale(NCT->p_right,key);
  30. }
  31. }
  32.  
  33. void add (school *site, int key)
  34. {
  35. school *newstu = new school;
  36. newstu->key = key;
  37. if (key > site->key)
  38. site->p_right = newstu;
  39. else
  40. site->p_left = newstu;
  41. }
  42.  
  43. void generate(school *NCT, int n)
  44. {
  45. int key;
  46. for (int i = 0; i<n;i++)
  47. {
  48. key = rand()%100;
  49. school *site = locale(NCT, key);
  50. add(site, key);
  51. }
  52. }
  53.  
  54. sortschoolout(school *NCT)
  55. {
  56. if(NCT->p_right == NULL && NCT->p_left == NULL)
  57. cout<<NCT->key;
  58. else if(NCT->p_right == NULL)
  59. {
  60. sortschoolout(NCT->p_left);
  61. cout<<NCT->key;
  62. }
  63. else if(NCT->p_left == NULL)
  64. {
  65. sortschoolout(NCT->p_right);
  66. cout<<NCT->key;
  67. }
  68. else
  69. {
  70. sortschoolout(NCT->p_left);
  71. cout<<NCT->key;
  72. sortschoolout(NCT->p_right);
  73. }
  74. }
  75.  
  76. main()
  77. {
  78. school *NCT = NULL;
  79. srand(time(NULL));
  80. generate(NCT,10);
  81. sortschoolout(NCT);
  82. }
  83.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'school* locale(school*, int)':
prog.cpp:22:10: error: reference to 'locale' is ambiguous
   return locale(NCT->p_left, key);
          ^
prog.cpp:15:9: note: candidates are: school* locale(school*, int)
 school *locale(school *NCT,  int key)
         ^
In file included from /usr/include/c++/5/bits/ios_base.h:41:0,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/5/bits/locale_classes.h:62:9: note:                 class std::locale
   class locale
         ^
prog.cpp:29:10: error: reference to 'locale' is ambiguous
   return locale(NCT->p_right,key);
          ^
prog.cpp:15:9: note: candidates are: school* locale(school*, int)
 school *locale(school *NCT,  int key)
         ^
In file included from /usr/include/c++/5/bits/ios_base.h:41:0,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/5/bits/locale_classes.h:62:9: note:                 class std::locale
   class locale
         ^
prog.cpp: In function 'void generate(school*, int)':
prog.cpp:49:17: error: reference to 'locale' is ambiguous
  school *site = locale(NCT, key);
                 ^
prog.cpp:15:9: note: candidates are: school* locale(school*, int)
 school *locale(school *NCT,  int key)
         ^
In file included from /usr/include/c++/5/bits/ios_base.h:41:0,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/5/bits/locale_classes.h:62:9: note:                 class std::locale
   class locale
         ^
prog.cpp: At global scope:
prog.cpp:54:26: error: ISO C++ forbids declaration of 'sortschoolout' with no type [-fpermissive]
 sortschoolout(school *NCT)
                          ^
stdout
Standard output is empty