Advertisement
Coriic

Untitled

Oct 25th, 2017
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 0.90 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 Lab4Tree is
  5.  
  6.   type Node is
  7.     record
  8.       Data : Integer := 0;
  9.       Left : access Node := Null;
  10.       Right : access Node := Null;
  11.     end record;
  12.  
  13.   type Node_Ptr is access all Node;
  14.  
  15.   procedure PrintNode(Tree : access Node_Ptr; Indent : String) is
  16.   begin
  17.     Put(Indent);
  18.     Put(Tree.Data, 4);
  19.     New_Line;
  20.     if Tree.Left /= Null then
  21.       PrintNode(Tree.Left, Indent & " ");
  22.     end if;
  23.     if Tree.Right /= Null then
  24.       PrintNode(Tree.Right, Indent & " ");
  25.     end if;
  26.   end PrintNode;
  27.  
  28.   procedure Print(Tree : access Node_Ptr) is
  29.     Tmp : access Node_Ptr := Tree;
  30.   begin
  31.     if Tree = Null then
  32.       Put_Line("Empty tree");
  33.     else
  34.       PrintNode(Tmp, "");
  35.     end if;
  36.   end Print;
  37.  
  38.   TreeInstance : Node_Ptr := Null;
  39.  
  40. begin
  41.   Print(TreeInstance);
  42. end Lab4Tree;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement