本文介绍了使用二叉搜索树查找dupilcate文件(没有错误但没有输出)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <dir.h>
#include <string.h>
#include <alloc.h>
#include <stdlib.h>
struct btreenode
{
struct btreenode *leftchild ;
char data[13] ; /* file name */
char *loc ; /* location of filename */
struct btreenode *rightchild ;
} *bt = NULL ;
void disktree( ) ;
int insert ( struct btreenode **, char*, char* ) ;
void main( )
{
char current_dir[32] ;
clrscr( ) ;
getcwd ( current_dir, 32 ) ;
chdir ( "\\" ) ;
disktree( ) ;
chdir ( current_dir ) ;
getch( ) ;
}
void disktree( )
{
struct ffblk file ;
int flag ;
char loc[80] ;
getcwd ( loc, 80 ) ;
flag = findfirst ( "*.*", &file, FA_NORMAL | FA_RDONLY | FA_HIDDEN |
FA_SYSTEM | FA_LABEL | FA_DIREC | FA_ARCH ) ;
while ( flag == 0 )
{
if ( file.ff_name[0] != '.' )
{
if ( file.ff_attrib == FA_DIREC && file.ff_fsize == 0 )
{
chdir ( file.ff_name ) ;
disktree( ) ;
chdir ( loc ) ;
}
else
insert ( &bt, loc, file.ff_name ) ;
}
flag = findnext ( &file ) ;
}
}
/* inserts a new node in a binary search tree */
int insert ( struct btreenode **sr, char* l, char* f )
{
char *p ;
int flag ;
if ( *sr == NULL )
{
*sr = ( struct btreenode * ) malloc ( sizeof ( struct btreenode ) ) ;
if ( *sr == NULL )
{
printf ( "\nOut of memory." ) ;
exit(1);
}
( *sr ) -> leftchild = NULL ;
( *sr ) -> rightchild = NULL ;
strcpy ( ( *sr ) -> data, f ) ;
p = ( char * ) malloc ( ( strlen ( l ) + 1 ) ) ;
if ( p == NULL )
{
printf ( "\nOut of memory." ) ;
exit(1);
}
strcpy ( p, l ) ;
( *sr ) -> loc = p ;
}
else
{
flag = strcmp ( ( *sr ) -> data, f ) ;
if ( flag == 0 )
{
printf ( "org: %s", ( *sr ) -> loc ) ;
if ( strlen ( ( *sr ) -> loc ) > 4 )
{
printf ( "\\" ) ;
printf ( "%s\n", ( *sr ) -> data ) ;
printf ("dup: %s", l ) ;
}
if ( strlen ( l ) > 4 )
{
printf ( "\\" ) ;
printf ( "%s\n\n", f ) ;
}
}
else if (flag < 0 )
{
insert ( &( ( *sr ) -> leftchild ), l, f ) ;
}
else
insert ( &( ( *sr ) -> rightchild ), l, f ) ;
}
return 0;
}
推荐答案
<br />
char data[13] ; /* file name */<br />
char current_dir[32] ;<br />
char loc[80] ; <br />
另外,如果你有任何输出的两个条件。它们是否正确?
Also, if you have two conditions around any output. Are they correct?
if ( strlen ( ( *sr ) -> loc ) > 4 )<br />
if ( strlen ( l ) > 4 )<br />
这篇关于使用二叉搜索树查找dupilcate文件(没有错误但没有输出)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!