Insert sorting, quick sorting, and php object-oriented knowledge

Source: Internet
Author: User
Insert sorting, quick sorting, and php object-oriented knowledge external sorting: memory cannot process such large data due to excessive data volumes, however, splitting big data into small data for sorting is external sorting. Use a disk to store files. & Nbsp; sorting algorithm: insert sorting method. Taking the array arrangement from small to large as an example, we first consider the array to be sorted as two parts: the first part is the insertion sorting, fast sorting, and php object-oriented knowledge.

External sorting method:

Because the data is too large, the memory cannot process such a large amount of data. however, to split big data into small data for sorting is external sorting. Use a disk to store files.

Sorting algorithm: insert sorting method.

Taking the array arrangement from small to large as an example, we first consider the array to be sorted as two parts: the first part is the ordered array. The default length is 1, that is, the element whose subscript is 0. All the following elements constitute an unordered array. each time the first element $ arr [I] of the unordered array is added to the ordered array, if $ arr [I] is greater than $ arr [i-1]; then add the element directly to the end (I .e. without any changes ), if $ arr [I] is less than $ arr [i-1], insert $ arr [I] to the proper location of the ordered array. when the ordered list reaches the size of the original array, the sorting process ends.

Sorting efficiency:

Bubble sorting <选择排序<插入排序< p>

The faster the efficiency, the more system resources are occupied. Quick sorting is fast, but it takes up a lot of memory because it involves many recursive calls.

Sample code for inserting sorting:

$ Arr = array (-,); echo count ($ arr)-1;

For ($ I = 1; $ I

If ($ arr [$ I]> $ arr [$ i-1]) {continue ;}

For ($ j = 0; $ j <$ I; $ j ++ ){

If ($ arr [$ I] <$ arr [$ j]) {

$ Temp = $ arr [$ I];

For ($ k = $ I; $ k >=$ j; $ k --){

$ Arr [$ k] = $ arr [$ k-1];

}

$ Arr [$ j] = $ temp;

}

} Echo"
". Print_r ($ arr )."
";

}

Quick sorting:

Function quicksort ($ seq ){

If (count ($ seq)> 1 ){

$ K = $ seq [0];

$ X = array ();

$ Y = array ();

For ($ I = 1; $ I

If ($ seq [$ I] <= $ k ){

$ X [] = $ seq [$ I];

} Else {

$ Y [] = $ seq [$ I];

}

}

$ X = quicksort ($ x); sorts array x

$ Y = quicksort ($ y );

Return array_merge ($ x, array ($ k), $ y );

} Else {

Return $ seq;

}

}

$ Arr = array (, 18 );

Print_r (quicksort ($ arr ));

 

The same page has multiple forms, and you do not know which form is submitted to php for processing. in this case, you can set a hidden control with the same name value and different values for each form. You can view the value of the hidden control to determine which form is submitted.

 

Php object-oriented programming

The php object is in the memory region: the php object name and object storage location are different, which is the same as java, therefore, in the php object-oriented part, you can fully apply the java idea. The object is stored in the heap, and the object name is stored in the stack like other common variables. Note that the object name is a reference to the object, that is, its value is actually the address of the object it points, so you can change the object it points to so that it points to a completely different object. Likewise, an object can have multiple object names, but note that, by modifying the member attribute of one of the object names, the member attributes pointed to by other object names will also change.

The basic type variables and object names are stored in the hidden area, while the objects are stored in the heap area. Then, the object name is a reference, that is, the value is an address, and the basic type variable indicates the address only when the & address character is added. Note the use of this keyword, especially the member variables of the partition type and the local variables in the member functions.

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.