SHARE
TWEET

BIN_TREE

a guest Oct 8th, 2018 133 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. note
  2.     description: "Summary description for {BIN_TREE}."
  3.     author: ""
  4.     date: "$Date$"
  5.     revision: "$Revision$"
  6.  
  7. class
  8.     BIN_TREE [G]
  9.  
  10. create
  11.     make
  12.  
  13. feature -- attributes
  14.     left : detachable BIN_TREE [G]
  15.     right : detachable BIN_TREE [G]
  16.     info : G
  17.  
  18. feature -- creation procedures
  19.     make (arg1: G )
  20.         do
  21.             info:= arg1
  22.         end
  23. feature -- queries
  24.     height : INTEGER
  25.         do
  26.             if (not attached left) and (not attached right) then
  27.                 Result:=1
  28.             end
  29.             if attached left as L then
  30.                 Result := L.height + 1
  31.             end
  32.             if attached right as R then
  33.                 if R.height > Result then
  34.                     Result := R.height + 1
  35.                 end
  36.             end
  37.         end
  38.  
  39. feature -- procedures
  40.     add_left(t : BIN_TREE [G]) -- replace left subtree by new one
  41.         do
  42.             if attached t as L then
  43.                 left := L
  44.             end
  45.  
  46.         end
  47.     add_right(t : BIN_TREE [G]) -- replace right subtree by new one
  48.         do
  49.             if attached t as R then
  50.                 right := R
  51.             end
  52.         end
  53. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top