Running hors.js

➕︎ Aa ➖︎ |Dark 1Dark 2Light|HackFira Code|Back to  PT Mono
// CPCS 223 Analysis & Design of Algorithms
// Horspool's string matching
// 2010, Dr. Muhammad Al-Hashimi



var pattern="BARBER";
var text = "JIM SAW ME IN A BARBERSHOP";
var pattern2 = "operatic";
var text2 = "As a staple of the operatic repertoire, Barber appears as number five on Opera America's list of the 20 most-performed operas in North America[4].";

document.write("<p>",horspool(pattern,text),"</p>");
document.write("<p>",horspool(pattern2,text2),"</p>");

// --------------------

function shiftTable(p)
{
	var m=p.length, table = [];
	
	// define your alphabet here
	var alphabet = " ,.0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	
	for (var j=0; j<alphabet.length; j++)
		table[alphabet[j]] = m;
		
	for (j=0; j<=m-2; j++)
		table[p[j]] = m-1-j;
	return table;
}

// --------------------
// straight implementation of textbook algorithm

function horspool(p,t)
{
	// fill your code here
	
	return -1
}