Ordering Words Alphabetically
This code shows how we can alphabetically order an array of words. I think it's pretty easy to understand. I also attached a 'counter' so we can track how many msecs the procedure will take. I added a function that will 'transform' all string to lower case as well as removing accented characters. This way we're sure the order will be correct.
AI
KI-Zusammenfassung: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Quellcode
Upload
<?php
function chgString($string) {
return strtolower(strtr($string,
"ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ",
"SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy"));
}
//if $order != 'ASC' result will be 'DESC'
$order="ASC";
//You can add as many as you want
$str[0]="john";
$str[1]="bettencourt";
$str[2]="francis";
$str[3]="susan";
$str[4]="mary";
$total=count($str);
$a=1;
while($a<$total+1){
$i=0;
while($i<$total+1){
if (strcmp(chgString($flag),chgString($str[$i]))<0){
$flagid=$i;
$flag=$str[$i];
}
$i++;
}
if ($order=="ASC"){
$strfinal = $str[$flagid]."<BR>".$strfinal;
}else{
$strfinal = $strfinal."<BR>".$str[$flagid];
}
$str[$flagid]="";
$flag="";
$a++;
}
//the result is helded in var $strfinal
$timeEnd=microtime();
$deltatime=($timeEnd-$timeStart);
$esttime=($deltatime*10000)/$total;
echo "<B>Alphabetical Result:</B><BR>$strfinal</B><BR>Done in $deltatime msecs";
echo "<BR>The estimated time for performing this operation on 10000 words is aprox: $esttime ms (can vary depending on the words size)";
?>
Originalkommentare (3)
Wiederhergestellt von der Wayback Machine