Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Recursive Classes - Design Pattern needed

I've got a class defined that instantiates itself internally. (It's a
simple binary tree implementation). Are there any OO gurus here can
help me to design the proper class structure so that I can track the
item count (# of nodes in the b-tree) and other statistics that would
apply to all instantiations ?
Do I just need to create a separate "parent" class that is
instantiated on the first instance of the bintree class ? I would
guess the parent class would house a Collection to track each instance
of the bintree, as well as the total count of the nodes.....correct ?
Am I on the right track ?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Recursive Classes - Design Pattern needed

In article om,
says...
I've got a class defined that instantiates itself internally. (It's a
simple binary tree implementation). Are there any OO gurus here can
help me to design the proper class structure so that I can track the
item count (# of nodes in the b-tree) and other statistics that would
apply to all instantiations ?
Do I just need to create a separate "parent" class that is
instantiated on the first instance of the bintree class ? I would
guess the parent class would house a Collection to track each instance
of the bintree, as well as the total count of the nodes.....correct ?
Am I on the right track ?


You could do what you propose. But for (almost) the same amount of
programming, I would add the information to each node. Now, you will
know how many elements each and every node contains. Something along
the lines of the pseudocode:

class BinTreeNode:

Dim Left as BinTreeNode, Right as BinTreeNode, _
Val, ChildCount as Integer

private function checkAndAdd(CurrNode as BinTreeNode, NewVal) _
as Boolean
if CurrNode is nothing then
set currnode=new BinTreeNode
with CurrNode
.val = NewVal
.ChildCount=0
end with
checkAndAdd=true
else
checkAndAdd=CurrNode.NewNodeAdded(NewVal)
end if
public function NewNodeAdded(NewVal) as Boolean
if me.val NewVal then NewNodeAdded=checkAndAdd(me.left,NewVal) _
else NewNodeAdded=checkAndAdd(me.right,NewVal)
if NewNodeAdded then me.ChildCount += 1
end function

Similarly, any delete function would have to subtract one from the
ChildCount property.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling Classes from Classes J Streger Excel Programming 2 March 23rd 07 01:13 PM
Is this a recursive problem? davegb Excel Programming 2 August 16th 06 07:53 PM
Automated contract received/accepted/loaded spreadsheet design HELP NEEDED Nick Marcell Excel Programming 4 May 25th 06 01:06 PM
Hyperlinks Inserted in Design Mode inactive once Exited Design Mod Craig Excel Programming 0 March 16th 05 04:53 PM
Enter Excel Design Mode and Exit Design Mode Bill Lunney Excel Programming 0 August 4th 03 07:48 AM


All times are GMT +1. The time now is 10:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"