Академический Документы
Профессиональный Документы
Культура Документы
HORSPOOL EN C++
Caractersticas
Es fcil de implementar.
(+1).
Lgica
texto,
el
salto
se
calcula
bmBc[c],
donde
ces
el
carcter
del
texto.
Cuando se encuentra una no ocurrencia o una ocurrencia total, al hacer las siguientes
comparaciones entre el patrn y el texto, el salto se calcula bmBc[c], donde ces el carcter
del patrn.
Descripcin
Es considerado el mejor algoritmo de bsqueda de un patrn en un texto en aplicaciones
usuales.
El algoritmo escanea los caracteres del patrn con el texto iniciando con el carcter ms a
la derecha.
En caso de una no ocurrencia o una ocurrencia total del patrn se usa una funcin
preprocesada para saltar:
Implementacin
/*
* C++ - Algoritmo de Boyer Moore Horspool
*
* Copyright 2014 Martin Cruz Otiniano
*
* Site: www.marcsdev.com
*/
#include<iostream>
#include <stdlib.h>
#include<string.h>
#include<time.h>
#define MAXT 1001
#define MAXP 1000
using namespace std;
char
char
signed int
signed int
texto[MAXT] ;
patron[MAXP] ;
rep ;
comp ;
// Preprocesamiento
// Bsqueda
j = 0;
while (j <= n - m)
{
c = T[j + m - 1] ;
if ( P[m - 1] == c && memcmp(P, T + j, m - 1) == 0 )
{
cout<<" * Encontrado en : "<< j + 1 << endl;
rep ++ ;
}
j = j + bmBC[c] ;
comp ++ ;
}
}
/*************************** Funcion Principal *****************************/
int main()
{
system("color 0B" );
float t1 , t2, tiempo ;
rep = 0 ;
cout<<endl ;
cout<<"\t "<<endl;
cout<<"\t ALGORITMO BOOYER M. HORSPOOL "<< endl ;
cout<<"\t ---------------------------------------------- "<< endl ;
cout<<"\t
"<<endl<<endl;
cout<<endl<<" Ingrese Texto : \n\t\t" ;
gets( texto ) ;
cout<<endl<<" Ingrese Patron : \n\t\t" ;
gets( patron ) ;
int n
int m
= strlen( texto ) ;
= strlen( patron ) ;
cout<<"\n__________________________________________________________"<<endl<<en
dl;
t1 = clock();
BMH( texto , n , patron , m ) ;
t2 = clock();
cout<<"\n__________________________________________________________"<<endl<<en
dl;
tiempo = (t2-t1)/100000 ;
cout<<endl<<" >> Tiempo de busqueda : "<< tiempo ;
if(rep == 0)
cout<<endl<<endl<<" >> Patron no encontrado ..! " ;
else
cout<<endl<<endl<<" >> Ocurrencias : "<< rep ;
cout<<endl<<endl<<" >> Comparaciones : "<< comp ;
cout<<"\n\n__________________________________________________________"<<endl<<
endl;
system("pause");
return 0;
}