How to write the bubble algorithm and quick algorithm (using arrays)

Source: Internet
Author: User
How to write the bubble algorithm and quick algorithm (using arrays)? how to write the bubble algorithm and quick algorithm (using arrays )??????


Reply to discussion (solution)

View the data structure.

Why don't I take the initiative to find the answer but wait for someone else to answer you? You can find a bunch of code under Baidu's 'php sorting algorithm Daquan '.

Okay, I'm wrong.

Function insert_sort ($ arr ){
$ Count = count ($ arr );
For ($ I = 1; $ I <$ count; $ I ++ ){
$ Tmp = $ arr [$ I];
$ J = $ I-1;
While ($ arr [$ j]> $ tmp ){
$ Arr [$ j + 1] = $ arr [$ j];
$ Arr [$ j] = $ tmp;
$ J --;
}
}
Return $ arr;
}
$ J. why --

Why?
Because the future is unknown, the security that has passed

Because the future is unknown, the security that has passed

Look for the data structure and take a look at the definitions of these two algorithms. then, try to tap into the code according to your own understanding, and finally look at other people's code to see whether they understand the same as others, this helps you.

Grace has been taught

Related Article

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.