Use defines for leaves
#define leaf1 {1,2,3}
etc.
On 13 =D1=CE=D7, 01:46, hankyp...@[EMAIL PROTECTED]
wrote:
> Hi All,
>
> I need a tree data structure for my application. It is the non -
> cyclic
> simple tree where i can have any number of children node and each
> child can recursively become a sub tree like a normal tree. =9ANow the
> thing is i can popullate my tree at compile time like a global data.
> Since
> i know my tree definition at compile time, instead of using pointers
> to point to siblings or child nodes, i am planning to use the array
> with undefined length like int a[] =3D {1,2}.
>
> Issue is if i declare complete tree at one place like this, my code
> become unreadable and unmanageable because of nested and high depth
> of
> tree. Even if i format code with 2 white space, it will become very
> big with around 10-20 levels and 20 nodes at each level. Also
> declaring each node with some logical name instead of an array
> element
> at some position will also make it easy to modify in future when
> required.
>
> I was planning to declare each node seperately and then use that in
> tree as =9Areference
> like
> =9AStructure Node leaf1 =3D {1,1,1};
> =9AStructure Node leaf2 =3D {1,1,1};
> =9AStructure Node leaf3 =3D {1,1,1};
>
> and then
> =9A =9A Structure Node =9Anode[] =9A=3D {1,1,1, leaf1, leaf2, leaf3};
>
> But the problem is i can not reference a variable like this as global
> data above my main method like this
>
> #include <stdio.h>
>
> =9AStructure Node leaf1 =3D {1,1,1};
> =9AStructure Node leaf2 =3D {1,1,1};
> =9AStructure Node leaf3 =3D {1,1,1};
>
> =9A Structure Node =9Anode[] =9A=3D {leaf1, leaf2, leaf3};
>
> int main()
> {
> =9A/// do processing;
> return 0;
>
> }
>
> It gives compilation error "error: initializer element is not
> constant". Pls let me know how can i handle such situation.
>
> Regards
> -
> --
> comp.lang.c.moderated - moderation address: c...@[EMAIL PROTECTED]
-- you
must
> have an appropriate newsgroups line in your header for your mail to be
see=
n,
> or the newsgroup name in square brackets in the subject line. =9ASorry.
--
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
-- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line. Sorry.


|