#include int InsReg( long pos, char ab ); long NRegistros = 9; char BTree_code[100] = { '*', 32, 32, 32, 32, 32, 32, 32, 32, '*', '*', '*'}; long BTree_pos [100] = { 10, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 11 }; long NRegTot = 12; #define ARRIBA 1 #define ABAJO 0 #define OK 0 #define ERROR 1 #define NO_ENC -1 int DelReg( long pos ); void main(void) { int pos, ab; pos = 0; printf("\n"); while ( pos < NRegTot ) { printf( " %c%d ", BTree_code[pos], BTree_pos[pos] ); pos++; } printf("\nIntroduzca posici¢n, y metodo ( ARRIBA=1, ABAJO=0 ) --->"); scanf( "%d %d", &pos, &ab ); if ( ab < 0 || ab > 1 ) return; // InsReg( pos, ab ); DelReg( pos ); pos = 0; printf("\n"); while ( pos < NRegTot ) { printf( " %c%d ", BTree_code[pos], BTree_pos[pos] ); pos++; } } int InsReg( long pos, char ab ) { NRegistros++; if ( pos >= (NRegistros-1) && NRegistros != 1) { NRegistros--; // ObtenError( 0x04 ); printf( "\nError registro no valido" ); return ERROR; } // char RegTot; long dir_libre; char codigo; /* fseek( handle_BTree, 0L, SEEK_END ); RegTot = ( ftell( handle_BTree ) - HeaderLen ) / ( sizeof(long) + sizeof(char) ); */ // Si hay fichas eliminadas, utilizamos sus direcciones intermedias. if ( (NRegTot - ( NRegistros - 1 ) ) > 0 ) { dir_libre = BTree_pos[NRegistros-1]; codigo = BTree_code[NRegistros-1]; /* fseek( handle_BTree, ( ( sizeof(long) + sizeof(char) ) * ( NRegistros ) ) + Header_Len ), SEEK_SET ); fread( &dir_libre, sizeof(long), 1, handle_BTree ); fread( &codigo, sizeof(char), 1, handle_BTree ); */ // si la supuesta ficha eliminada, no lo esta, utilizamos la siguiente if ( codigo != '*' ) dir_libre = NRegistros; } else dir_libre = ( NRegistros - 1 ); // |<---------- RegTot ----------->| // |<----- NRegistros ---->| | // ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ¿ // ³ 1 ³ 2 ³ 5 ³ 6 ³ 4 ³ 3 ³ * ³ * ³ ³ ³ ³ ³ ³ // ÀÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÙ // // 2 up Âpos+1 // ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ¿ // ³ 1 ³ 2 ³ * ³ 5 ³ 6 ³ 4 ³ 3 ³ * ³ ³ ³ ³ ³ ³ // ÀÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÙ // 2 down Âpos // ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ¿ // ³ 1 ³ * ³ 2 ³ 5 ³ 6 ³ 4 ³ 3 ³ * ³ ³ ³ ³ ³ ³ // ÀÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÙ unsigned long avance; avance = ( NRegistros - 1 ); while ( avance > ( pos + ab ) ) { /* fseek( handle_BTree, ((sizeof(long)+sizeof(char))*(avance-1))+HeaderLen, SEEK_SET); fread( &dirch , sizeof(long), 1, handle_BTree ); fread( &codch , sizeof(char), 1, handle_BTree ); fwrite( &dirch , sizeof(long), 1, handle_BTree ); fwrite( &codch , sizeof(char), 1, handle_BTree ); */ BTree_code[avance] = BTree_code[avance-1]; BTree_pos [avance] = BTree_pos [avance-1]; avance--; } if ( ( NRegistros - 1 ) == 0 ) //fseek( handle_BTree, HeaderLen, SEEK_SET); {BTree_code[0] = ' '; BTree_pos[0] = dir_libre;} else //fseek( handle_BTree, ((sizeof(long)+sizeof(char))*(pos + ab))+HeaderLen, SEEK_SET); {BTree_code[pos+ab] = ' '; BTree_pos[pos+ab] = dir_libre;} /* codch = ' '; fwrite( &dir_libre, sizeof(long), 1, handle_BTree ); fwrite( &codch , sizeof(char), 1, handle_BTree ); */ /* fseek( handle_BDatos, ( ( SizeReg*dir_libre ) + HeaderLen ), SEEK_SET ); fwrite( datos, SizeReg, 1, handle_BDatos ); fseek( handle_BTree, 14L, SEEK_SET ); fwrite( &NRegistro, sizeof(long), 1, handle_BTree ); */ } int DelReg( long pos ) { long old_dir; char new_cod; /* NRegistros++; if ( pos >= (NRegistros-1) && NRegistros != 1) */ NRegistros--; if ( pos >= (NRegistros+1) ) { NRegistros++; printf( "\nError registro no valido\n" ); return ERROR; } /* fseek( handle_BTree, ( ( sizeof(long) + sizeof(char) ) * pos ) + Header_Len ), SEEK_SET ); fread( &old_dir, sizeof(long), 1, handle_BTree ); */ old_dir = BTree_pos[pos]; // |<---------- RegTot ----------->| // |<----- NRegistros ---->| | // ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ¿ // ³ 1 ³ 2 ³ 5 ³ 6 ³ 4 ³ 3 ³ * ³ * ³ ³ ³ ³ ³ ³ // ÀÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÙ // unsigned long avance; avance = pos; while ( avance < (NRegistros /*+ 1*/) ) { /* fseek( handle_BTree, ((sizeof(long)+sizeof(char))*(avance+1))+HeaderLen, SEEK_SET); fread( &dirch , sizeof(long), 1, handle_BTree ); fread( &codch , sizeof(char), 1, handle_BTree ); fseek( handle_BTree, ((sizeof(long)+sizeof(char))*( avance ))+HeaderLen, SEEK_SET); fwrite( &dirch , sizeof(long), 1, handle_BTree ); fwrite( &codch , sizeof(char), 1, handle_BTree ); */ BTree_code[avance] = BTree_code[avance+1]; BTree_pos [avance] = BTree_pos [avance+1]; avance++; } /* fseek( handle_BTree, ((sizeof(long)+sizeof(char))*(NRegistros+1))+HeaderLen, SEEK_SET); new_cod = '*'; fwrite( &old_dir, sizeof(long), 1, handle_BTree ); fwrite( &new_cod, sizeof(char), 1, handle_BTree ); */ BTree_code[avance] = '*'; BTree_pos [avance] = old_dir; /* fseek ( handle_BTree, (sizeof(char)*14), SEEK_SET ); fwrite( &NRegistros, sizeof(long), 1, handle_BTree ); */ }