php bubble sort quick sort, php bubble sort
/******
1) Bubble sort: Exchange values in pairs, with the smallest value on the left, just like the lightest bubble on the top.
2) Exchange the entire column of numbers once, with the smallest number on the far left. Each time, you can get the smallest number among the remaining numbers. The "popped" numbers form an ordered interval, and the remaining numbers are The values below form an unordered interval, and the value of each element in the ordered interval is smaller than that of the unordered interval.
3) Quick sort: base number, left and right arrays, recursive call, merge.
4) Insertion sort: The sorting interval is divided into two parts, the left side is ordered and the right side is unordered. Take the first element from the right interval and insert it into the left interval. If this element is larger than the rightmost element of the left interval, leave it where it is. If this element is smaller than the rightmost element in the left range, it will be inserted at the original position of the rightmost element. At the same time, the rightmost element will be shifted one position to the right. The calculator will be reduced by one and will be compared with the previous element again until the previous element is smaller than the previous element. To insert elements as small as possible, repeat the above steps.
6) Pay attention to the processing of interval endpoint values, and the subscript of the first element of the array is 0.
***/
<span><br />$a</span>=<span>array</span>('3','8','1','4','11','7'<span>); </span><span>print_r</span>(<span>$a</span><span>); </span><span>$len</span> = <span>count</span>(<span>$a</span><span>); </span><span>//</span><span>从小到大</span> <span>for</span>(<span>$i</span>=1;<span>$i</span><<span>$len</span>;<span>$i</span>++<span>) { </span><span>for</span>(<span>$j</span>=<span>$len</span>-1;<span>$j</span>>=<span>$i</span>;<span>$j</span>--<span>) </span><span>if</span>(<span>$a</span>[<span>$j</span>]<<span>$a</span>[<span>$j</span>-1<span>]) {</span><span>//</span><span>如果是从大到小的话,只要在这里的判断改成if($b[$j]>$b[$j-1])就可以了</span> <span>$x</span>=<span>$a</span>[<span>$j</span><span>]; </span><span>$a</span>[<span>$j</span>]=<span>$a</span>[<span>$j</span>-1<span>]; </span><span>$a</span>[<span>$j</span>-1]=<span>$x</span><span>; } } </span><span>print_r</span>(<span>$a</span><span>); </span><span>//</span><span>另一种方法 从小到大</span> <span>$b</span>=<span>array</span>('4','3','8','9','2','1'<span>); </span><span>$len</span>=<span>count</span>(<span>$b</span><span>); </span><span>for</span>(<span>$k</span>=1;<span>$k</span><<span>$len</span>;<span>$k</span>++<span>) { </span><span>for</span>(<span>$j</span>=<span>$len</span>-1,<span>$i</span>=0;<span>$i</span><<span>$len</span>-<span>$k</span>;<span>$i</span>++,<span>$j</span>--<span>) </span><span>if</span>(<span>$b</span>[<span>$j</span>]<<span>$b</span>[<span>$j</span>-1<span>]){ </span><span>//</span><span>如果是从大到小的话,只要在这里的判断改成if($b[$j]>$b[$j-1])就可以了</span> <span>$tmp</span>=<span>$b</span>[<span>$j</span><span>]; </span><span>$b</span>[<span>$j</span>]=<span>$b</span>[<span>$j</span>-1<span>]; </span><span>$b</span>[<span>$j</span>-1]=<span>$tmp</span><span>; } </span><span>print_r</span>(<span>$b</span><span>); </span><span>echo</span> " "<span>; } </span><span>//</span><span>下面的这个执行效率更高</span> <span>function</span> maopao(<span>$arr</span><span>) { </span><span>$len</span> = <span>count</span>(<span>$arr</span><span>); </span><span>for</span>(<span>$i</span>=1; <span>$i</span><<span>$len</span>; <span>$i</span>++)<span>//</span><span>最多做n-1趟排序</span> <span> { </span><span>$flag</span> = <span>false</span>; <span>//</span><span>本趟排序开始前,交换标志应为假</span> <span>for</span>(<span>$j</span>=<span>$len</span>-1;<span>$j</span>>=<span>$i</span>;<span>$j</span>--<span>) { </span><span>if</span>(<span>$arr</span>[<span>$j</span>]<<span>$arr</span>[<span>$j</span>-1])<span>//</span><span>交换记录</span> {<span>//</span><span>如果是从大到小的话,只要在这里的判断改成if($arr[$j]>$arr[$j-1])就可以了</span> <span>$x</span>=<span>$arr</span>[<span>$j</span><span>]; </span><span>$arr</span>[<span>$j</span>]=<span>$arr</span>[<span>$j</span>-1<span>]; </span><span>$arr</span>[<span>$j</span>-1]=<span>$x</span><span>; </span><span>$flag</span> = <span>true</span>;<span>//</span><span>发生了交换,故将交换标志置为真</span> <span> } } </span><span>if</span>(! <span>$flag</span>)<span>//</span><span>本趟排序未发生交换,提前终止算法</span> <span>return</span> <span>$arr</span><span>; } } </span><span>$shuz</span> = <span>array</span>('2','4','1','8','5'<span>); </span><span>$bb</span> = maopao(<span>$shuz</span><span>); </span><span>print_r</span>(<span>$bb</span><span>); </span><span>//</span><span> 快速排序</span> <span>function</span> kuaisu(<span>$arr</span><span>){ </span><span>$len</span> = <span>count</span>(<span>$arr</span><span>); </span><span>if</span>(<span>$len</span> <= 1<span>){ </span><span>return</span> <span>$arr</span><span>; } </span><span>$key</span> = <span>$arr</span>[0<span>]; </span><span>$left_arr</span> = <span>array</span><span>(); </span><span>$right_arr</span> = <span>array</span><span>(); </span><span>for</span>(<span>$i</span>=1; <span>$i</span><<span>$len</span>;<span>$i</span>++<span>){ </span><span>if</span>(<span>$arr</span>[<span>$i</span>] <= <span>$key</span><span>){ </span><span>$left_arr</span>[] = <span>$arr</span>[<span>$i</span><span>]; }</span><span>else</span><span>{ </span><span>$right_arr</span>[] = <span>$arr</span>[<span>$i</span><span>]; } } </span><span>$left_arr</span> = kuaisu(<span>$left_arr</span><span>); </span><span>$right_arr</span> = kuaisu(<span>$right_arr</span><span>); </span><span>return</span> <span>array_merge</span>(<span>$left_arr</span>, <span>array</span>(<span>$key</span>), <span>$right_arr</span><span>); } </span><span>$arr</span> = <span>array</span>(23,98,54,2,9,62,34<span>); </span><span>print_r</span>(kuaisu(<span>$arr</span>));

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software