gjc@batserver.cs.uq.oz (Cumming) (10/06/89)
There appears to be an error in the implementation of INT_BINTREE. The classes
below, written by myself and dependent upon INT_BINTREE produce erroneous
output.
MY_INT_BINTREE is simply INT_BINTREE with node_action redefined to print a
integer value and create taking an integer rather than an INT_COMPAR parameter.
TEST_BINDING simply takes integer input and inserts that input into a tree of
integers (or INT_COMPARs) and calls infix to print the current tree in infix
order.
As one can see, the first integer entered is printed correctly. The further
entries are inserted in the correct place but are not printed correctly,
though further tests have shown that the random value printed to represent the
entered value is not always entered in the correct order.
Script started on Thu Oct 5 12:19:45 1989
[1] es test_binding
Eiffel configuration manager
(version 2.1)
Pass 1 on class test_binding
Pass 1 on class my_int_bintree
Pass 2 on class test_binding
Interface may have changed.
Pass 2 on class my_int_bintree
Interface may have changed.
Pass 3 on class test_binding
Pass 3 on class my_int_bintree
Pass 4 on class test_binding
Pass 4 on class my_int_bintree
C-compiling test_binding
C-compiling my_int_bintree
Generating and C-compiling temporary main file.
Linking system (17 classes)
es: System assembly complete
[2] test_binding
Please enter integer value: 46
46,
Please enter integer value: 78
46,317584,
Please enter integer value: 2
298916,46,317584,
Please enter integer value: 1
298808,298916,46,317584,
Please enter integer value: 99
298808,298916,46,298616,317584,
Please enter integer value: 0
[3] exit
script done on Thu Oct 5 12:22:07 1989
class MY_INT_BINTREE export
start, finish,
is_leaf, arity,
left, right,
has_left, has_right, has_both, has_none,
insert_value, contains_value,
preorder, infix, postorder, node_action,
screen
inherit
INT_BINTREE
rename
Create as bintree_Create
redefine
node_action
feature
Create (i: INTEGER) is
-- Create node with value i and no children
local
iv:INT_COMPAR;
do
screen.Create;
iv.Create(i);
bintree_Create(iv);
ensure
node_value = iv;
left.Void and right.Void
end; -- Create
screen:STD_FILES;
node_action (v: INT_COMPAR) is
-- Operation on node value,
-- to be defined by descendant classes.
-- Here it is defined as an empty operation.
-- Redefine this procedure in descendant classes if useful
-- operations are to be performed during traversals.
do
screen.putint(v.value);
screen.putstring(",");
end; -- node_action
end -- INT_BINTREE
class TEST_BINDING
feature
io:STD_FILES;
b:MY_INT_BINTREE;
AskForInt:INT_COMPAR is
local
int:INTEGER;
ic:INT_COMPAR;
do
io.new_line;
io.putstring ("Please enter integer value: ");
io.readint;
int:=io.lastint;
io.next_line;
ic.create(int);
Result:=ic;
end; -- AskForInt
create is
-- Execute sequence of interactive commands
local
entry:INT_COMPAR;
do
io.create;
from
entry:=AskForInt;
b.Create(entry.value);
until entry.value=0 loop
b.infix;
entry:=AskForInt;
if entry.value/=0 then
b.insert_value(entry.value);
end; -- if entry.value/=0 then
end;
io.forget;
end; -- create
end -- class TEST_BINDING