fork download
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. struct node{
  6. char q[20];
  7. int nomer;
  8. node *l, *r;
  9. };
  10. node *tree = NULL;
  11.  
  12. int Delete(node **t, char target[], int target1);
  13. void push(char a[], int n, node **t);
  14. void search(char a[], node *t);
  15. void print (node *t, int u);
  16.  
  17. void push(char a[], int n, node **t){
  18. if((*t) == NULL){
  19. *t = new node;
  20. strcpy_s((*t) -> q, a);
  21. (*t) -> nomer = n;
  22. (*t)->l = (*t)->r = NULL;
  23. return;
  24. }
  25. if(strcmp(a,(*t) -> q) > 0)
  26. push(a, n, &((*t)->r));
  27. else if(strcmp(a,(*t) -> q) < 0)
  28. push(a, n, &((*t)->l));
  29. }
  30. void search(char a[], node *t){
  31. if(t == NULL)
  32. return;
  33. if(strcmp(a, t->q) == 0){
  34. strcpy_s(t->q, "Andrey");
  35. return;
  36. }
  37. search(a, t->l);
  38. search(a, t->r);
  39. }
  40. int Delete(node **t, char target[]){
  41. if ( (*t) == 0 )
  42. return 0;
  43. if (strcmp((*t)->q,target) == 0 )
  44. {
  45. if(((*t)->l!=0)&&((*t)->r!=0))
  46. {
  47. node *P=new node;
  48. P=(*t)->l;
  49. if(P->r==0)
  50. {
  51. strcpy_s((*t)->q, P -> q);
  52. (*t)->nomer = P->nomer;
  53. (*t)->l = P->l;
  54. }
  55. else
  56. {
  57. while (P->r->r!=0)
  58. P = P->r;
  59. strcpy_s((*t)->q, P->r->q);
  60. (*t)->nomer = P->nomer;
  61. P->r=0;
  62. }
  63. return 0;
  64. }
  65. else
  66. return 1;
  67. }
  68. if(Delete( &((*t)->l), target))
  69. {
  70. if ( (*t)->l->l == 0 )
  71. (*t)->l = (*t)->l->r;
  72. else
  73. (*t)->l = (*t)->l->l;
  74. return 0;
  75. }
  76. if(Delete(&((*t)->r), target))
  77. {
  78. if ( (*t)->r->l == 0 )
  79. (*t)->r = (*t)->r->r;
  80. else
  81. (*t)->r = (*t)->r->l;
  82. return 0;
  83. }
  84. return 0;
  85. }
  86.  
  87. void print (node *t,int u)
  88. {
  89. if (t==NULL){
  90. return;
  91. }
  92.  
  93. print(t->l,++u);
  94. for (int i=0;i<u;++i)
  95. printf(" - ");
  96. printf("%s %d\n",t->q, t->nomer);
  97. u--;
  98.  
  99. print(t->r,++u);
  100. }
  101.  
  102.  
  103. void main(){
  104. int n, n1;
  105. char name[20];
  106. printf("Enter nuber of elements ");
  107. scanf_s("%d", &n);
  108.  
  109. for(int i = 0; i < n; i++){
  110. printf("\nEnter name: ");
  111. fflush(stdin);
  112. gets_s(name);
  113. printf("\nEnter nomber: ");
  114. scanf_s("%d", &n1);
  115. push(name, n1, &tree);
  116. }
  117. printf("your tree\n");
  118. print(tree, 0);
  119.  
  120. char a[20];
  121. printf("Enter name for search ");
  122. fflush(stdin);
  123. gets_s(a);
  124. search(a, tree);
  125.  
  126. printf("\n\nyour tree\n");
  127. print(tree, 0);
  128.  
  129. char b[20];
  130. printf("\nenter name for delete: ");
  131. fflush(stdin);
  132. gets_s(b);
  133. Delete(&tree, b);
  134. printf("\n\nyour tree after deletion of element\n");
  135. print(tree, 0);
  136. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void push(char*, int, node**)’:
prog.cpp:20:24: error: ‘strcpy_s’ was not declared in this scope
   strcpy_s((*t) -> q, a);
                        ^
prog.cpp: In function ‘void search(char*, node*)’:
prog.cpp:34:26: error: ‘strcpy_s’ was not declared in this scope
   strcpy_s(t->q, "Andrey");
                          ^
prog.cpp: In function ‘int Delete(node**, char*)’:
prog.cpp:51:29: error: ‘strcpy_s’ was not declared in this scope
     strcpy_s((*t)->q, P -> q);
                             ^
prog.cpp:59:30: error: ‘strcpy_s’ was not declared in this scope
     strcpy_s((*t)->q, P->r->q);
                              ^
prog.cpp: At global scope:
prog.cpp:103:11: error: ‘::main’ must return ‘int’
 void main(){
           ^
prog.cpp: In function ‘int main()’:
prog.cpp:107:18: error: ‘scanf_s’ was not declared in this scope
  scanf_s("%d", &n);
                  ^
prog.cpp:112:14: error: ‘gets_s’ was not declared in this scope
   gets_s(name);
              ^
prog.cpp:123:10: error: ‘gets_s’ was not declared in this scope
  gets_s(a);
          ^
stdout
Standard output is empty