INDEX CLUSTER FEATURES SHORT FRAMES NO FRAMES

indexing

description: "Binary tree: each node may have a left child and a right ", "child "
title: "EiffelBase: library of reusable components for Eiffel. ", "Based on EiffelBase library for ISE Eiffel, ", "used with permission. "
project: "EiffelBase Library"
copyright: "(c) 1986-1997 Interactive Software Engineering Inc. ", "Modifications and extensions: ", "(c) 1997 Object Tools ", "All rights reserved. Duplication and distribution prohibited", "May be used only with Visual Eiffel under terms of user ", "license "
key: binary_tree, tree, fixed_tree
cluster: eiffelbase
class BINARY_TREE [G]
inherit

CELL [G]
end

TREE [G]
redefine
child_after,
child_remove,
fill_list,
is_leaf,
parent,
subtree_count,
subtree_has
end
creation

make
feature -- Initialization

make (v: G)
-- Create a root node with value v
ensure
is_root
is_leaf
feature -- Access

parent: like Current

child_index: INTEGER

left_child: like parent

right_child: like parent

left_item: G
-- Value of left child
require
has_left: left_child /= void

right_item: G
-- Value of right child
require
has_right: right_child /= void

first_child: like parent
-- Left child

last_child: like parent
-- Right child

child: like parent
-- Child at cursor position

child_cursor: CURSOR
-- Current cursor position

left_sibling: like parent
-- Left neighbor, if any

right_sibling: like parent
-- Right neighbor, if any
feature -- Measurement

arity: INTEGER
-- Number of children
ensure
valid_arity: Result <= 2
feature -- Status report

child_after: BOOLEAN
-- Is there no valid child position to the right of cursor?

is_leaf, has_none: BOOLEAN
-- Are there no children?

has_left: BOOLEAN
-- Has current node a left child?
ensure
Result = (left_child /= void)

has_right: BOOLEAN
-- Has current node a right child?
ensure
Result = (right_child /= void)

has_both: BOOLEAN
-- Has current node two children?
ensure
Result = (has_left and has_right)
feature -- Element change

put_left_child (n: like parent)
-- Set `left_child' to `n'.
require
no_parent: n = void or else n.is_root

put_right_child (n: like parent)
-- Set `right_child' to `n'.
require
no_parent: n = void or else n.is_root

child_put, child_replace (v: G)
-- Put `v' at current child position.

put_child, replace_child (n: like parent)
-- Put `n' at current child position.
feature -- Removal

remove_left_child
ensure
not has_left

remove_right_child
ensure
not has_right

child_remove

prune (n: like parent)
feature -- Cursor movement

child_go_to (p: CURSOR)
-- Move cursor to child remembered by `p'.

child_start
-- Move to first child.

child_finish
-- Move cursor to last child.

child_forth
-- Move cursor to next child.

child_back
-- Move cursor to previous child.

child_go_i_th (i: INTEGER)
-- Move cursor to `i'-th child.
feature -- Duplication

duplicate (n: INTEGER): like Current
-- Copy of sub-tree beginning at cursor position and
-- having min (`n', `arity' - `child_index' + 1)
-- children.

duplicate_all: like Current
invariant

child_capacity = 2
end -- class BINARY_TREE

INDEX CLUSTER FEATURES SHORT FRAMES NO FRAMES