/* 木のトラバサール */ void treewalk(tnode *p) { if(p != NULL) { treewalk(p->right); printf("%s\n", p->name); treewalk(p->left); } }
static void treewalk( Node *tree ) { if ( tree != NULL ) { treewalk( tree->left ); int i; printf( "'%s' is on lines of {", tree->word ); for ( i = 0; i < tree->size; i++ ) { printf( "%d, ", tree->lines[ i ] ); } printf( "}\n" ); treewalk( tree->right ); } }
int main(){ char dat[12]; struct tnode *root; root = NULL; while(scanf(" %s",dat) != EOF){ root = gentree(root,dat); } treewalk(root); return 0; }
/* main prog */ int main( int argc, char **argv ) { char word[ MAX_WORD_LEN ]; Node *tree = NULL; while ( getword( word, MAX_WORD_LEN ) != EOF ) { if ( isalpha( *word ) && !isnoise( word ) ) { tree = addtree( tree, word ); } } treewalk( tree ); treefree( tree ); return 0; }
int main(void) { char dat[12]; tnode *root; root = NULL; while(scanf("%s", dat) != EOF) { if(strcmp("q", dat) == 0) break; root = gentree(root, dat); } treewalk(root); return 0; }
int main(int argc, char **argv) { struct node *rootp; int i; int array[15] = {50, 12, 18, 70, 41, 19, 91, 1, 7, 6, 81, 65, 55, 20, 0}; for (i = 0; i < 15; i++) { treeadd(&rootp, array[i]); } treewalk(rootp); printf("\n"); treefree(rootp); return 0; }
void treewalk(struct node *p) { treewalk(p->left); printf("%d ", p->value); treewalk(p->right); }
/* d e c k ( ) make a COMGEOM deck for current list of objects */ void deck(register char *prefix) { register int i; nns = nnr = 0; /* Create file for solid table. */ if ( prefix != 0 ) { /* !!! this seems wrong. st_file is a pointer into a bu_vls */ bu_strlcpy(st_file, prefix, 80); bu_strlcat(st_file, ".st", 80); } else bu_strlcpy( st_file, "solids", 80 ); if ( (solfd = creat( st_file, 0644 )) < 0 ) { perror( st_file ); bu_exit( 10, NULL ); } /* Target units (a2, 3x) */ ewrite( solfd, bu_units_string(dbip->dbi_local2base), 2 ); blank_fill( solfd, 3 ); /* Title */ if ( dbip->dbi_title == NULL ) ewrite( solfd, objfile, (unsigned) strlen( objfile ) ); else ewrite( solfd, dbip->dbi_title, (unsigned) strlen( dbip->dbi_title ) ); ewrite( solfd, LF, 1 ); /* Save space for number of solids and regions. */ savsol = lseek( solfd, 0L, 1 ); blank_fill( solfd, 10 ); ewrite( solfd, LF, 1 ); /* Create file for region table. */ if ( prefix != 0 ) { bu_strlcpy(rt_file, prefix, 80); bu_strlcat(rt_file, ".rt", 80); } else bu_strlcpy(rt_file, "regions", 80); if ( (regfd = creat( rt_file, 0644 )) < 0 ) { perror( rt_file ); bu_exit( 10, NULL ); } /* create file for region ident table */ if ( prefix != 0 ) { bu_strlcpy(id_file, prefix, 80); bu_strlcat(id_file, ".id", 80); } else bu_strLcpy(id_file, "region_ids", 80); if ( (ridfd = creat( id_file, 0644 )) < 0 ) { perror( id_file ); bu_exit( 10, NULL ); } itoa( -1, buff, 5 ); ewrite( ridfd, buff, 5 ); ewrite( ridfd, LF, 1 ); /* Initialize matrices. */ MAT_IDN( identity ); /* Check integrity of list against directory and build card deck. */ for ( i = 0; i < curr_ct; i++ ) { struct directory *dirp; if ( (dirp = db_lookup( dbip, curr_list[i], LOOKUP_NOISY )) != DIR_NULL ) { #if 1 treewalk( curr_list[i] ); #else cgobj( dirp, 0, identity ); #endif } } /* Add number of solids and regions on second card. */ (void) lseek( solfd, savsol, 0 ); itoa( nns, buff, 5 ); ewrite( solfd, buff, 5 ); itoa( nnr, buff, 5 ); ewrite( solfd, buff, 5 ); /* Finish region id table. */ ewrite( ridfd, LF, 1 ); (void) printf( "====================================================\n" ); (void) printf( "O U T P U T F I L E S :\n\n" ); (void) printf( "solid table = \"%s\"\n", st_file ); (void) printf( "region table = \"%s\"\n", rt_file ); (void) printf( "region identification table = \"%s\"\n", id_file ); (void) close( solfd ); (void) close( regfd ); (void) close( ridfd ); /* reset starting numbers for solids and regions */ delsol = delreg = 0; /* XXX should free soltab list */ }