Guest User

Untitled

a guest
May 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. with Bucket_Search_Elementary_Tree_Package;
  2. with Ada.Strings.Unbounded;
  3. with Ada.Strings.Unbounded.Text_IO;
  4. with Ada.Text_IO;
  5.  
  6. use Bucket_Search_Elementary_Tree_Package;
  7. use Ada.Strings.Unbounded;
  8. use Ada.Strings.Unbounded.Text_IO;
  9. use Ada.Text_IO;
  10.  
  11. procedure Test_The_Bucket is
  12.  
  13. Tree : BSE_Tree;
  14.  
  15. procedure BSE_Insert
  16. (T : in out BSE_Tree) is
  17. Source : File_Type;
  18. Read : Unbounded_String;
  19. To_Insert : Unbounded_String;
  20. Current_Char : Character;
  21. begin
  22. Open (Source, In_File, "BSE_Insert.txt");
  23. while not End_Of_File (Source) loop
  24. Read := Get_Line (Source);
  25. for I in 1 .. Length (Read) loop
  26. Current_Char := Element (Read, I);
  27. if Current_Char = ' '
  28. or Character'Pos (Current_Char) = 10
  29. or Character'Pos (Current_Char) = 13 then
  30. Insert (T, To_Insert);
  31. To_Insert := To_Unbounded_String ("");
  32. else
  33. Append (To_Insert, Current_Char);
  34. end if;
  35. end loop;
  36. Insert (T, To_Insert);
  37. To_Insert := To_Unbounded_String ("");
  38. end loop;
  39. Close (Source);
  40. Put_Line ("BSE_Insert executed successfully.");
  41. end BSE_Insert;
  42.  
  43. procedure BSE_Delete
  44. (T : in out BSE_Tree) is
  45. Source : File_Type;
  46. Read : Unbounded_String;
  47. To_Delete : Unbounded_String;
  48. Current_Char : Character;
  49. begin
  50. Open (Source, In_File, "BSE_Delete.txt");
  51. while not End_Of_File (Source) loop
  52. Read := Get_Line (Source);
  53. for I in 1 .. Length (Read) loop
  54. Current_Char := Element (Read, I);
  55. if Current_Char = ' '
  56. or Character'Pos (Current_Char) = 10
  57. or Character'Pos (Current_Char) = 13 then
  58. Delete (T, To_Delete);
  59. To_Delete := To_Unbounded_String ("");
  60. else
  61. Append (To_Delete, Current_Char);
  62. end if;
  63. end loop;
  64. Delete (T, To_Delete);
  65. To_Delete := To_Unbounded_String ("");
  66. end loop;
  67. Close (Source);
  68. Put_Line ("BSE_Delete successfully executed.");
  69. end BSE_Delete;
  70.  
  71. procedure BSE_Find
  72. (T : in BSE_Tree) is
  73. Source : File_Type;
  74. Read : Unbounded_String;
  75. To_Find : Unbounded_String;
  76. Current_Char : Character;
  77. begin
  78. Open (Source, In_File, "BSE_Find.txt");
  79. while not End_Of_File (Source) loop
  80. Read := Get_Line (Source);
  81. for I in 1 .. Length (Read) loop
  82. Current_Char := Element (Read, I);
  83. if Current_Char = ' '
  84. or Character'Pos (Current_Char) = 10
  85. or Character'Pos (Current_Char) = 13 then
  86. if Find (T, To_Find) then
  87. Put_Line (To_Find);
  88. end if;
  89. To_Find := To_Unbounded_String ("");
  90. else
  91. Append (To_Find, Current_Char);
  92. end if;
  93. end loop;
  94. if Find (T, To_Find) then
  95. Put_Line (To_Find);
  96. end if;
  97. To_Find := To_Unbounded_String ("");
  98. end loop;
  99. Close (Source);
  100. end BSE_Find;
  101.  
  102. A, B : Unbounded_String;
  103.  
  104.  
  105. begin
  106.  
  107. Tree := new BSE_Element;
  108. BSE_Insert (Tree);
  109. -- Put_Line ("The Tree now looks as following:");
  110. -- Put (Tree);
  111. Put_Line ("The tree contains" & Size (Tree)'Img & " different elements.");
  112. BSE_Delete (Tree);
  113. -- Put_Line ("The Tree now looks as following:");
  114. -- Put (Tree);
  115. Put_Line ("The tree contains" & Size (Tree)'Img & " different elements.");
  116. -- Put_Line ("The tree still contains thw following words from the ");
  117. -- Put ("BSE_Find File:");
  118. -- New_Line;
  119. -- BSE_Find (Tree);
  120. Clear (Tree);
  121. BSE_Insert (Tree);
  122. -- Put (Tree);
  123. end Test_The_Bucket;
Add Comment
Please, Sign In to add comment