Re: General tree assignment in C



On Jan 31, 3:05 pm, "Ivica" <prljavi_blu...@xxxxxxxxxxx> wrote:
"kwikius" <a...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message

news:ee7b6153-cebc-4437-85da-25c560143cec@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Why does it have to be C?.

trees are classic examples where an OOP style works well. You really
need a language that supports runtime polymorphism in the language,
e.g Java, C++, C#

C is very poor for this use (its possible but ugly) which is I would
guess why there are few examples.

regards
Andy Little

Well, I understood what you meant to say but... Since I am a student, mr.
professor decided that we should use plain C and that makes us feel like a
idiots because deadline is coming in around one week and nobody have written
that.

FWIW the important directory tree concept that is not stated AFAICS in
the spec (or I misssed it) is the concept of a path, which is a list
of identifiers of nodes in the tree. You could start by designing a
path either as a list of strings or as a string with some separator,
and then some useful operations on it, such as peeling off
identifiers, adding an identifier, etc.

For nodes the classic structure might be
something like
(bear in mind I'm used to C++ so this may not be valid C)

struct node {
node * parent; // may be empty for root
char* name; // assume some text identifier
node * children; // empty for leaf, else list of children
data * data ;// empty for directory
};

You then need to get your path and tree structure working together,
e.g examine your path peeling off the identifiers, and walking the
tree comparing the identifiers in the path with the tree identifiers.

You also need to be able to create nodes, destroy nodes, find children
and provide useful error handling

Unfortunately this is all very hard work in C, but its all possible.

HTH

regards
Andy Little





.



Relevant Pages

  • Re: basque and circassian
    ... The alleged correlation between genes and language is fraudulent (as I ... This dual tree lists 38 populations, ... There is not much overwhelming agreement among linguists about the ...
    (sci.lang)
  • Re: GMP vs. straight C arithmetic
    ... ordinary data structures that don't impose an additonal performance ... Side-effects are another crucial part of the language. ... > Take the tree structure example I gave earlier. ... determined at compile time, is this a compile time error? ...
    (comp.programming)
  • Re: case-sensitivity
    ... national and language boundaries, because it contained, say, romanized Chinese ... rather than unicode encoded kanji? ... (which evidently sucks even for English-only prose and programming). ... you have to translate the identifiers and comments in a common language anyway ...
    (comp.lang.scheme)
  • Re: case-sensitivity
    ... How about the fact that although ASCII isn't enough for most of the ... and although most of programming languages ... delightful alternatives that language desingers have come up so far ... identifiers have vastly different graphical requirements from ...
    (comp.lang.scheme)
  • Re: Chemistry from a Bahai perspective
    ... Hi Matt. ... Naming conventions generally hold that the name of an item should ... A tree is named and generalized into human language so that, most often, we ...
    (soc.religion.bahai)