#include #include #include #include "bst.h" BST_EL *tree = NULL; void read_file( char *s ) { FILE *fp; char tmp[80]; BST_EL *ptr; BST_EL new_el; fp = fopen( s, "r" ); if( fp == NULL ) { printf( "Impossibile aprire %s\n", s ); exit( 1 ); } while( fscanf( fp, "%s", tmp ) != EOF ) { ptr = search( tree, tmp ); if( ptr == NULL ) { printf( "==> %s\n", tmp ); new_el.word = tmp; new_el.freq = 1; insert( &tree, &new_el ); } else { printf( "Aggiorno %s\n", tmp ); ptr->freq++; } } fclose( fp ); } void print_freq( void ) { printf( "VISITA IN-ORDER\n" ); visit_in_order( tree ); printf( "VISITA PRE-ORDER\n" ); visit_pre_order( tree ); printf( "VISITA POST-ORDER\n" ); visit_post_order( tree ); } int main( int argc, char **argv ) { if( argc < 2 ) { printf( "Uso: frequenze nomefile\n" ); exit( 1 ); } read_file( argv[1] ); print_freq(); dispose( &tree ); return( 0 ); }