Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include "RB.hpp"
  4. #include "Treap.hpp"
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main() {
  10.  
  11.  
  12.  
  13. RB *rb_tree = new RB();
  14. Treap *treap = new Treap();
  15.  
  16. /*
  17. rb_tree->insert(0);
  18. treap->insert(0); ---- Добавление ключа
  19.  
  20. rb_tree->remove(0);
  21. treap->remove(0); ---- Удаление ключа
  22.  
  23. rb_tree->print();
  24. treap->print_sym();
  25. treap->print_direct(); Отображение деревьев на экране
  26. */
  27.  
  28.  
  29.  
  30. int array[100*100];
  31. for (int i=0; i<100*100; i++)
  32. array[i]=0;
  33. int temp;
  34.  
  35. FILE *f;
  36. int k=0;
  37. int ii=0;
  38. int count=0;
  39. if ((f = fopen("test", "rb")) == NULL)
  40. {
  41. printf("Ошибка открытия файла");
  42. }
  43. else
  44. {
  45. for (k=0;k<n;k++)
  46. {
  47. fscanf("%d", &temp);
  48.  
  49. for (ii=0; ii<100*100; ii++) {
  50. if (array[ii] == temp)
  51. break;
  52. }
  53. if (ii != 100*100)
  54. continue;
  55.  
  56. array[count]=temp;
  57. count++;
  58. }
  59. }
  60.  
  61.  
  62.  
  63.  
  64. fclose(f);
  65. return ;
  66.  
  67. int array[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  68.  
  69. std::cout << "RB Tree->insert\n";
  70. std::cout << "Treap->insert\n";
  71. for (int i=0; i<10; i++) {
  72. std::cout << " " << array[i] << std::endl;
  73. rb_tree->insert(array[i]);
  74. treap->insert(array[i]);
  75. }
  76.  
  77. std::cout << "\nRB Tree->print():\n";
  78. rb_tree->print();
  79.  
  80. std::cout << "\nTreap->print_direct():\n";
  81. treap->print_direct();
  82.  
  83. std::cout << "\nRB Tree->remove\n";
  84. std::cout << "Treap->remove\n";
  85. for (int i=0; i<10; i++) {
  86. std::cout << " " << array[i] << std::endl;
  87. rb_tree->remove(array[i]);
  88. treap->remove(array[i]);
  89. }
  90.  
  91. std::cout << "\nRB Tree->print():\n";
  92. rb_tree->print();
  93.  
  94. std::cout << "\nTreap->print_direct():\n";
  95. treap->print_direct();
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement