Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the basic algorithms of php

Shulou Source: shulou.com Published: 2022-06-03 07:40:05 11月10日 Update

This article mainly explains "what are the basic algorithms of php". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the basic algorithms of php.

Four basic algorithms of php: bubbling, selection, insertion and fast sorting

Many people say that the algorithm is the core of the program, a program is better than bad, the key is the pros and cons of the program algorithm. As an entry-level phper, although I have little contact with algorithms. But I think we still need to master the four basic algorithms of bubble sorting, insertion sorting, selection sorting and fast sorting. Here is an analysis of the four methods according to my own understanding.

Requirements: use bubble sort method, fast sort method, select sort method, insert sort method to sort the values in the following array according to the order from small to small.

$arr (1 arr 43 5 4 6 2 21 6 6 7 8 36 6 7 6 39)

1. Bubbling sorting method

* thought analysis: the method, as its name suggests, is like bubbling, with the largest number coming out of the array at a time.

* for example: 2Jing 4jue 1 / / the first bubble is 4

The second bubble is 2.

* 1pr 2pm 4 / / that's what happened in the end.

* Code implementation:

The copy code is as follows:

$arr=array (1 arr=array 43 5 4 6 2 21 6 6 7 8 36 6 7 6 39)

Function getpao ($arr)

{

$len=count ($arr)

/ / set an empty array to receive bubbles.

/ / the cycle of this layer controls the number of wheels that need to bubble.

For ($iSuppli.

Tags: Sort element array location code minimum selection algorithm control loop ruler foundation idea right program part two number content inner layer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Microsoft Shulou Tech Info MariaDB macOS