comp.lang.ada
 help / color / mirror / Atom feed
* Postfix notation with a binary Tree
@ 2004-04-16 13:12 tchou
  2004-04-16 16:37 ` Robert I. Eachus
  0 siblings, 1 reply; 2+ messages in thread
From: tchou @ 2004-04-16 13:12 UTC (permalink / raw)


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?

Thanx,

Tchou.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Postfix notation with a binary Tree
  2004-04-16 13:12 Postfix notation with a binary Tree tchou
@ 2004-04-16 16:37 ` Robert I. Eachus
  0 siblings, 0 replies; 2+ messages in thread
From: Robert I. Eachus @ 2004-04-16 16:37 UTC (permalink / raw)


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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-04-16 16:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-16 13:12 Postfix notation with a binary Tree tchou
2004-04-16 16:37 ` Robert I. Eachus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox