binary tree and condition parser...

D

Daniel Bass

Using VC#.Net, I want to take a statement, that loosely follows the rules of
an SQL'a "WHERE" statement, and determine whether that statement is true or
false.

For example:

( ( Head = 'abc') AND ( Type = 'Text' ) ) OR ( Loc = '123' )

I envisioned a binary tree, and using a stack object, I'd parse through the
statement to populate the tree to something like this. (hope it looks right
for you!)


OR
/ \
/ \
/ \
AND =
/ \ / \
/ \ Loc '123'
/ \
= =
/ \ / \
/ \ Type 'Text'
/ \
Head 'abc'


The statements themselves are compared to an XML document I'm parsing...

I got into the binary tree class to try and populate it it some way, but
couldn't get an algorithm to work.

Once the tree was populated in the above fashion, I planned to do a depth
first search, factoring up each branch, (if Head == 'bcd' for example, then
the tree would look like this after one node factor.

OR
/ \
/ \
/ \
AND =
/ \ / \
/ \ Loc '123'
/ \
FALSE =
/ \
Type 'Text'


And so this process would occur until my root value had either a TRUE or a
FALSE, which was the value of the statement, when compared to the XML
document I'm evaluating.

Something that's also confusing me a little is the C# syntax. Coming from
C++ I knew the condition of each created and destroyed object via the
pointers I used to access them, but that seems to be out the window, so
would setting a node to the root, say, destroy the object it was currently
assigned to? Because I wouldn't want this because the object would still
exist in the tree structure.

I'd appreciate any ideas, input, suggestions as to where to go from here.

Thanks for your time.
Daniel.
 
B

Bret Mulvey

It wouldn't destroy the object if the object is still in the tree and you
can still "get to it." If you can't get to it because you don't have any
references to it any more (coming at it from another direction in the tree)
it would get garbage-collected.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top