From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: Postfix notation with a binary Tree
Date: Fri, 16 Apr 2004 12:37:24 -0400
Date: 2004-04-16T12:37:24-04:00 [thread overview]
Message-ID: <88idnWdjLZRZlh3dRVn-jw@comcast.com> (raw)
In-Reply-To: <970fcf2a.0404160512.4ad1d128@posting.google.com>
tchou wrote:
> Hello everyone,
>
> Which type should I use to do a binary tree for calculation, using a
> postfix notation?
>
> '+' '-' -> character
> 6876, 23.42, 1 -> Integer OR string
>
> Is a conversion to string the only / best solution?
No, you can use either tagged types or variant records to create a
heterogenous data structure. For this application I prefer variant records:
type Content_Type is (Operator, Integer_Value, Float_Value, ...);
type Node;
type Node_Pointer is access all Node;
type Node(Content: Content_Type) is record
Left, Right: Node_Pointer;
case Content_Type is
when Operator => Op: Character;
when Integer_Value => Int: Integer;
...
end case;
end record;
--
Robert I. Eachus
"The terrorist enemy holds no territory, defends no population, is
unconstrained by rules of warfare, and respects no law of morality. Such
an enemy cannot be deterred, contained, appeased or negotiated with. It
can only be destroyed--and that, ladies and gentlemen, is the business
at hand." -- Dick Cheney
prev parent reply other threads:[~2004-04-16 16:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-16 13:12 Postfix notation with a binary Tree tchou
2004-04-16 16:37 ` Robert I. Eachus [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox