From: Gerald Ang <tmang@student.ecu.edu.au>
Subject: help for my project
Date: 2000/05/09
Date: 2000-05-09T00:00:00+00:00 [thread overview]
Message-ID: <3917F194.F6C1BB73@student.ecu.edu.au> (raw)
Help is needed for my assignment. Below is a copy of the specificaton
code, please help with the Procedure Add.
with Ada.Text_IO;
with Unchecked_Deallocation;
generic
type Symbol is (<>);
package Symbolized_Search_Tree is
type Tree is private;
type Symbol_Array is array(Integer range <>) of Symbol;
type Sequence is access Symbol_Array;
type Sequence_Array is array(Integer range <>) of Sequence;
package Symbol_IO is new Ada.Text_IO.Enumeration_IO(Enum => Symbol);
procedure Add(A_Tree: in out Tree;
Symbols: in Symbol_Array;
Result: out Integer);
-- adds Symbols' non-shared elements to A_Tree and sets marker
--
-- if no Symbols
-- then
-- Result:= -1
-- return
-- end if
--
-- if no A_Tree nodes
-- then
-- create root node, non-leaf nodes, leaf node
-- assign Symbols' elements to root node, non-leaf nodes
-- assign True to leaf node marker
-- Result:= number of nodes created
-- return
-- end if
--
-- determine number of Symbols' elements contained in A_Tree
--
-- if A_Tree contains all Symbols' elements and True marker
-- then
-- Result:= -2
-- return
-- end if
--
-- if A_Tree contains all Symbols' elements and False marker
-- then
-- assign True to marker
-- Result:= 0
-- return
-- end if
--
-- if A_Tree contains some of Symbols' elements
-- then
-- augment differing non-root node
-- create non-leaf nodes, leaf nodes
-- assign Symbols' tail elements to non-root node, non-leaf nodes
-- assign True to leaf node marker
-- Result:= number of nodes augmented/created
-- return
-- end if
--
-- if A_Tree contains none of Symbols' elements
-- then
-- augment root node
-- create non-leaf nodes, leaf node
-- assign Symbols' elements to root node, non-leaf nodes
-- assign True to leaf node marker
-- Result:= number of nodes augmented/created
-- return
-- end if
private
type Node(Length: Integer);
type Tree is access Node;
type Tree_Array is array (Integer range <>) of Tree;
type Node(Length: Integer) is
record
Marker: Boolean;
Symbols: Symbol_Array(1..Length);
Subtrees: Tree_Array(1..Length);
end record;
-- a leaf node has Length = 0 and Marker = True
-- a partial-leaf node has Length > 0 and Marker = True
-- a non-leaf node has Length > 0 and Marker = False
-- for 1 <= I <= Length-1, Node.Symbols(I) < Node.Symbols(I+1)
Null_Tree: constant Tree:= null;
procedure Deallocate is
new Unchecked_Deallocation(Object=>Node,
Name=>Tree);
end Symbolized_Search_Tree;
next reply other threads:[~2000-05-09 0:00 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-05-09 0:00 Gerald Ang [this message]
2000-05-09 0:00 ` help for my project Robert Dewar
2000-05-09 0:00 ` nickerson
2000-05-10 0:00 ` Geoff Bull
2000-05-10 0:00 ` Robert Dewar
2000-05-13 0:00 ` Larry Kilgallen
2000-05-11 0:00 ` wv12
2000-05-09 0:00 ` John English
2000-05-09 0:00 ` Ted Dennison
2000-05-09 0:00 ` Gerald Ang
2000-05-09 0:00 ` Robert Dewar
2000-05-09 0:00 ` Ted Dennison
2000-05-10 0:00 ` yahoo
2000-05-10 0:00 ` Jeff Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox