Write a sort algorithm that can be a bubble sort or a quick sort, 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)

Source: Internet
Author: User
Tags array sort

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.