N
Nick Keighley
"Nick Keighley"<[email protected]> ha scritto nel messaggioA possibly dumb question: Given a labeled or unlabeled tree
(in the sense of graphs), how could one best use C to describe it?
what form is it in now or how are you going to enter it?
/* tree.c */
#include<stdio.h>
typedef struct tree_tag
{
char *data;
struct tree_tag *left;
struct tree_tag *right;
} Tree;
void walk (Tree *tree)
{
if (tree != NULL)
{
printf ("%s ", tree->data);
walk (tree->left);
walk (tree->right);
}
}
int main (void)
{
Tree yggdrasil[] =
{
{"red",&yggdrasil[1],&yggdrasil[2]},
{"blue",&yggdrasil[3],&yggdrasil[4]},
{"black", 0, 0},
{"yellow", 0, 0},
{"green", 0, 0}
};
walk (yggdrasil);
return 0;
}
Error E2063 tree1.c 27: Illegal initialization in function main
*** 1 errors in Compile ***I'm surprised! It compiled and executed ok for me with an old Windows
compiler. And on gcc unless I stuck -pedantic on... ok fair cop
It's perfectly valid C.
ah yes, even with pedantic I only got
D:\bin\net>gcc -W -Wall -pedantic -ansi tree.c
tree.c: In function `main':
tree.c:27: warning: initializer element is not computable at load time
[several times]