bubble sort (array sort)
functionBubble_sort ($array){ $count=Count($array); if($count<= 0)return false; for($i= 0;$i<$count;$i++){ for($j=$count-1;$j>$i;$j--){ if($array[$j] <$array[$j-1]){ $tmp=$array[$j]; $array[$j] =$array[$j-1]; $array[$j-1] =$tmp; } } } return $array;}
Quick Sort (array sort)
functionQuicksort$array) { if(Count($array) <= 1)return $array; $key=$array[0]; $left _arr=Array(); $right _arr=Array(); for($i= 1;$i<Count($array);$i++){ if($array[$i] <=$key) $left _arr[] =$array[$i]; Else $right _arr[] =$array[$i]; } $left _arr= Quicksort ($left _arr); $right _arr= Quicksort ($right _arr); return Array_merge($left _arr,Array($key),$right _arr);}
. Write a function that iterates through all subdirectories and sub-files in the specified directory (hint: Recursive method can be used)
functionDir_all ($path ) { $handler=Opendir($path); while(false!==($tmp=Readdir($handler))) { if(Is_dir( "$path/$tmp" )) { if($tmp=="." |$tmp=="..")Continue; Echo $tmp." <br>/n "; Dir_all ("$path/$tmp"); } Else { Echo $tmp." <br>/n "; } }}
Write out two regular expressions that match the mailbox address and URL. Similar to the following:
// Email Address: [Email protected] URL address: http://(hint: Use standard regular expressions, that is, the regular handler function of the Preg_* class in PHP can parse the regular)// mailbox://w+ ([-+.] /w+) *@/w+ ([-.] /w+) */./w+ ([-.] /w+) */Url:/^http:////[/w]+/.[ /w]+[/s]*/
< Span style= "COLOR: #000000" > < Span style= "COLOR: #800080" > < Span style= "COLOR: #800080" > < Span style= "COLOR: #800080" >
The
Writes a sort algorithm, either bubbling or fast, assuming that the object being sorted is a dimension array. (Hint: You cannot use the system already has functions, please also carefully recall the basic knowledge previously learned)