473,408 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Unsorted Infinite Child Tree

I"m looking to find (or if I can't, make) a real simple tree with a
few characteristics
- no sorting, I want to insert a node and specify the parent
- infinite children

These characteristics should accurately reflect a menu tree. That's
what I'm going for.

The only real functionality I need is proper insertion (and as a
corrollary find). Deletion is not neccessary.

Any thoughts or points of reference? If anyone knows of such a
structure and it exists already, please link to it. Thanks.

Jun 27 '07 #1
4 1894
On 27 Jun, 16:55, Travis <travis.bow...@gmail.comwrote:
I"m looking to find (or if I can't, make) a real simple tree with a
few characteristics
- no sorting, I want to insert a node and specify the parent
- infinite children

These characteristics should accurately reflect a menu tree. That's
what I'm going for.

The only real functionality I need is proper insertion (and as a
corrollary find). Deletion is not neccessary.

Any thoughts or points of reference? If anyone knows of such a
structure and it exists already, please link to it. Thanks.
I would use boost::graph. you can easily define that kind
of a tree with it. it also provides bunch of algorithms, like
breadth_first_search and depth_first_search. it doesn't provide
insert per se but it is easy to implement with add_vertex, add_edge.

regards

DS
Jun 27 '07 #2
Travis wrote:
I"m looking to find (or if I can't, make) a real simple tree with a
few characteristics
- no sorting, I want to insert a node and specify the parent
- infinite children
I'm not sure what's out there, but if you need to roll your own, and you
need infinite children, I'd go with leftmost child/sibling.
Something like this (note: I'm just hacking this out, so...)

template<typename T>
struct Node
{
Node* lm_child;
Node* next_sibling;
T data;
Node(const T& val)
: lm_child(NULL), next_sibling(NULL), data(val) { }
// remaining methods and access control left as an
// exercise for the reader :-)
};
Jun 27 '07 #3
Okay here's what I whipped up while waiting for a response. Haha.

http://cpp.sourceforge.net/?show=37716

Seems to work for my needs, just curious if anyone here looks at it
and says "oh dear God that's terrible".

It's basically just a tree of nodes with each node having a vector of
children. The find is probably the most inefficient part but it's
recursive so maybe that helps a bit.

Thanks.

Jun 27 '07 #4
On 27 Jun, 18:11, Travis <travis.bow...@gmail.comwrote:
Okay here's what I whipped up while waiting for a response. Haha.

http://cpp.sourceforge.net/?show=37716

Seems to work for my needs, just curious if anyone here looks at it
and says "oh dear God that's terrible".
I haven't looked at your code (sorry, I'm at work and I can't download
stuff easily).
It's basically just a tree of nodes with each node having a vector of
children.
you mean it is a node with vector of nodes.
The find is probably the most inefficient part but it's
recursive so maybe that helps a bit.
you got it completely wrong in assuming that recursion might
make your code more efficient. you should avoid recursion because
it is much more inefficient than loops. also, if you have deep
recursion
you can run out of stack space, stack size is fixed.

some algorithms look nicer when implemented with recursion but that
doesn't make them more efficient.

you can always replace recursion with a loop.
Thanks.
regards

DS

Jun 28 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Suzanne Vogel | last post by:
Hi, I've been trying to write a function to test whether one class is derived from another class. I am given only id's of the two classes. Therefore, direct use of template methods is not an...
9
by: Ken | last post by:
I am trying to create one image using JavaScript; then later in the script remove the image - not just remove the src. The following creates the image, but I have been unable to remove it. How...
0
by: clintonG | last post by:
The implementation I am working with has several child elements that have the same name; <link> for example. When the XML is loaded into a tree control and a click event is used on a node in the...
3
by: feng | last post by:
Hi, I have a MDI container that contains a treeview and a child form. Clicking on a tree node will open the child form. Right now, the focus stays with the treeview, even after the child form...
7
by: amruta | last post by:
the code below dows not let me get the parent child view... all the nodes are show in one line only... also i need them to be collasped ... Thanks ..
2
by: RJN | last post by:
Hi I need help in writing a recursive function. My table structure is as below. InstanceId LevelId ParentId 100 1 null 101 2 ...
2
by: Jack | last post by:
Hello, I am trying use a TreeView with checkboxes. I would like to check more than one node and allow all child nodes of selected nodes to be checked or unchecked with the parent is checked. ...
4
by: Gregory Piñero | last post by:
Hi, Would anyone be able to tell me why my function below is getting stuck in infinite recusion? Maybe I'm just tired and missing something obvious? def...
8
by: Pivot_Tables | last post by:
Hi, I have created a recursive SQL Query in DB2 and it works fine until some point in the tree where the data gets into infinite loop. Below are some sample data from my relationship table. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.