Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- indexing
- description : "Node of a binary search tree."
- date: "$Date$"
- revision: "$Revision$"
- class
- NODE
- create
- make
- feature
- value: INTEGER
- left, right: NODE
- make (v: INTEGER)
- -- Create node with value `v'.
- do
- value := v
- ensure
- value_set: value = v
- end
- traverse
- -- Traverse tree starting from Current.
- do
- if left /= Void then
- left.traverse
- end
- Io.put_string (value.out + " ") -- print in order of values
- if right /= Void then
- right.traverse
- end
- end
- set_children (l, r: NODE)
- -- Set left and right childred.
- do
- left := l
- right := r
- end
- put (n: INTEGER)
- -- Insert a node with value `n' at the right place.
- do
- if n < value then
- if left = Void then
- create left.make (n)
- else
- left.put (n)
- end
- else
- if right = Void then
- create right.make (n)
- else
- right.put (n)
- end
- end
- end
- has (n: INTEGER): BOOLEAN
- -- Returns true if and only if `n' is in the tree rooted by Current.
- do
- if n = value then
- Result := True
- elseif n < value and left /= Void then
- Result := left.has (n)
- elseif n >= value and right /= Void then
- Result := right.has (n)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement