ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i would like to ask if for C(not c++) there are
written any free libraries(opensource) for creating
trees with variable number of child nodes(siblings) on
each father node.
and the nodes could have a linked list as a
member.
also if you don't know such a library please let
me know where am i most likely to find a library
like this.
i would write one from zero but...i would be wasting
time.
i just need a variable number of children on each node.
b-trees not fit my needs.
Why not?
Quote:
In computer science, B-trees are tree data structures that are most commonly found in databases and filesystems. B-trees keep data sorted and allow amortized logarithmic time insertions and deletions.
The idea behind B-trees is that internal nodes can have a variable number of child nodes within some pre-defined range.
You might need a combination of data structures. For example, you might need a Tree where one elment of each Leaf consists of a List. The constructor and destructor of the Leaf object could certainly manage an attached List.
Now, having said that ... always begin by very carefully describing to yourself: "what,nothow you need to do."
In other words, without right-away committing to the notion that what you need is "a tree," look at just what you need to be able to put into this structure and what kinds of queries you need to make of it, what kinds of changes you need to make to it, and any sequence-order requirements.
I tried to be versatile, so you can change the compare function to use w/ the value (the 2nd parameter passed in tree_insert). I also let you associate every value entered into the tree w/ some data, so it can be used as an associative array or something similar. Also, you can use some linked list implementation, for example, as the data, and have something else as the value. Here is a very simple example,
The 2 files your interested in are tree.c and tree.h. tree_test.c you can ignore. Just copy tree.c and tree.h over to whatever project you want to use them in, and compile them as part of your source.
You can also search by index (position) using tree_item so you can iterate over all the elements in a tree.
ALL operations are done in O(log n), including tree_item and tree_size. If you want more info, check out tree.c, it has much more detailed explainations of each function in tree.h than tree.h itself.
Here is al library for directed graphs. And because a tree is a subset of these graphs (well actually it is undirected, but you can simply work around this restriction)it may fit you needs. But I must confess, that I never used it myself.
EDIT:
Oh, I just read, that this library also supports undirected graphs, and with this you can model your tree without any "workaround."
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.