ahi hay algo por favor respetar al autor de este codigo ok!
//**************************************
//
// Name: Binary search
// Description:Binary search algorithm f
// unction. Takes an array as an argument a
// nd the element
to be searched for in the array. Returns '1' if found, '0' if not.
The code can be modified slightly to return the array index of the found element.
// By: Bhushan.
//
//This code is copyrighted and has // limited warranties.Please see http://
//
www.Planet-Source-Code.com/vb/scripts/Sh // owCode.asp?txtCodeId=755&lngWId=8 //for details. //**************************************
//
<?php
function BinarySearch($ArrayToSearch/*array to search through*/, $SearchFor/*element to search for*/)
{
sort($ArrayToSearch);//must sort the array
//index
$first=0;
$last=count($ArrayToSearch)-1;
$mid=($first+$last)/2;
$SearchFor=strval(trim($SearchFor));
while
(
($first<=$last)&&
(strval(trim($ArrayToSearch[$mid]))!=$SearchFor)
)
{
if(strcmp(strtolower($SearchFor),strtolower($ArrayToSearch[$mid]))<0)
{$last=$mid-1;}//search the upper half
else
if(strcmp(strtolower($SearchFor),strtolower($ArrayToSearch[$mid]))>0)
{$first=$mid+1;}//search the lower half
$mid=($first+$last)/2;//new mid point
}
if(strval(trim($ArrayToSearch[$mid]))==$SearchFor)
//{return $mid;} --> if your objectiv
// e is to return the index
{return 1;}
else
{return 0;}
//{return -1;} --> if your objective
// is to return the index
}
?>
///ordenamiento burbuja
//**************************************
//
// Name: bubble sort
// Description:simple bubble sort
// By: Bhushan.
//
//This code is copyrighted and has // limited warranties.Please see http://
//
www.Planet-Source-Code.com/vb/scripts/Sh // owCode.asp?txtCodeId=756&lngWId=8 //for details. //**************************************
//
<?php
function bubblesort($a1,$a2)
{
for($i = sizeof($a1); $i >= 1; $i--)
{
for($j = 1; $j <= $i; $j++)
{
if($a1[$j-1] > $a1[$j])
{
$t = $a1[$j-1];
$t2 = $a2[$j-1];
$a1[$j-1] = $a1[$j];
$a2[$j-1] = $a2[$j];
$a1[$j] = $t;
$a2[$j] = $t2;
}
}
}
}
?>
//otro ordenamiento burbuja
//**************************************
//
// Name: Bubble Sort Algorithm
// Description:Simple bubble sort algori
// thm.
// By: Alberto Sartori
//
//This code is copyrighted and has // limited warranties.Please see http://
//
www.Planet-Source-Code.com/vb/scripts/Sh // owCode.asp?txtCodeId=761&lngWId=8 //for details. //**************************************
//
<?php
//BUBBLE SORT ALGORITHM
function bubblesort(&$incoming_vector,$outgoing_vector) {
$chain=0;
$a=0;
for($a=$outgoing_vector; $a>0; $a--) {
$chain=1;
for($v=0; $v<$outgoing_vector ;$v++) {
if ($incoming_vector[$v] > $incoming_vector[$v+1]) {
$aux=$incoming_vector[$v];
$incoming_vector[$v]=$incoming_vector[$v+1];
$incoming_vector[$v+1]=$aux;
$chain=$v;
}
}
$outgoing_vector=$chain;
}
}
?>
//ordenamiento quk sort
//**************************************
//
// Name: Quck Sort function
// Description:Quck Sort function.
// By: Bhushan.
//
//This code is copyrighted and has // limited warranties.Please see http://
//
www.Planet-Source-Code.com/vb/scripts/Sh // owCode.asp?txtCodeId=757&lngWId=8 //for details. //**************************************
//
// Quck Sort function
function qsort( &$rowdata, $sortBy, $first, $last )
{
$lo = $first;
$up = $last;
$i = $first + $last;
$bound = strval($rowdata[($i - $i%2)/2][$sortBy]);
while ( $lo <= $up)
{
while( ($lo <= $last - 1) && (strval($rowdata[$lo][$sortBy]) < $bound))
{
$lo++;
}
while (($up >= 1) && ($bound < strval($rowdata[$up][$sortBy])) )
{
$up--;
}
if ($lo < $up)
{
$tmp = $rowdata[$up];
$rowdata[$up] = $rowdata[$lo];
$rowdata[$lo] = $tmp;
$up--;
$lo++;
}
else
{
$lo++;
}
}
if ($first < $up) qsort($rowdata, $sortBy, $first, $up);
if ($up + 1 < $last) qsort($rowdata, $sortBy, $up + 1, $last);
}
//////////////////////////////////////////////////////////////////////////
usar funcion FILE para capturar el txt a un array,
faltan algunas cosas relacionadas con la programacion, pero va luegooo...
nos vemos.