Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.00 KB | None | 0 0
  1. with Ada.Text_IO, Ada.Integer_Text_IO;
  2. use Ada.Text_IO, Ada.Integer_Text_IO;
  3.  
  4. procedure ProgB is
  5.    
  6.     type Element is
  7.         record
  8.             Data : Integer := 0;
  9.             Left : access Element := Null;
  10.             Right : access Element := Null;
  11.         end record;
  12.  
  13.     type Element_Ptr is access all Element;
  14.    
  15.     procedure PrintTree(Tree : access Element) is
  16.    
  17.     begin
  18.         if Tree /= Null then
  19.             Put_Line(Element.Data'Img);
  20.             PrintTree(Element.Left);
  21.             PrintTree(Element.Right);
  22.         end if;
  23.        
  24.     end PrintTree;
  25.    
  26.     procedure WstawBst(Tree : in out Element_Ptr, Val : in Integer) is
  27.        
  28.         E : Element_Ptr := new Element'(Val,Null,Null);
  29.        
  30.     begin
  31.        
  32.         if Tree = Null then
  33.             Tree := E;
  34.         elsif Tree.Data == Val then null;
  35.         elsif Tree.Data > Val then
  36.            
  37.             if Tree.Left \= Null then
  38.                 WstawBst(Tree.Left,Val);
  39.             elsif Tree.Left := E;
  40.             end if;
  41.         else
  42.             if Tree.Right \= Null then
  43.                 WstawBst(Tree.Right,Val);
  44.             elsif Tree.Right := E;
  45.        
  46.             end if;
  47.         end if;
  48.        
  49.     end WstawBst;
  50.  
  51.    
  52.    
  53. begin  
  54.    
  55. end ProgB;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement