Re: General tree assignment in C
- From: kwikius <andy@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 07:58:00 -0800 (PST)
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
.
- References:
- General tree assignment in C
- From: Ivica
- Re: General tree assignment in C
- From: kwikius
- Re: General tree assignment in C
- From: Ivica
- General tree assignment in C
- Prev by Date: Re: General tree assignment in C
- Next by Date: Re: General tree assignment in C
- Previous by thread: Re: General tree assignment in C
- Next by thread: Re: General tree assignment in C
- Index(es):
Relevant Pages
|