


PHP implements the sequential storage structure of linear tables
<code><span><span>class</span><span>SqList</span> {</span><span>public</span><span>$elem</span>; <span>public</span><span>$length</span>; <span>public</span><span>$size</span>; } <span><span>class</span><span>Linear</span> {</span><span>const</span> LIST_INIT_SIZE = <span>10</span>; <span>const</span> LIST_INCREMENT = <span>5</span>; <span>private</span><span>$list</span> = <span>null</span>; <span>/** * 构造一个空的线性表 */</span><span>public</span><span><span>function</span><span>initList</span><span>()</span> {</span><span>$this</span>-><span>list</span> = <span>new</span> SqList(); <span>$this</span>-><span>list</span>->elem = <span>array</span>(); <span>$this</span>-><span>list</span>->length = <span>0</span>; <span>$this</span>-><span>list</span>->size = <span>self</span>::LIST_INIT_SIZE; <span>return</span><span>true</span>; } <span>/** * 销毁线性表 */</span><span>public</span><span><span>function</span><span>destoryList</span><span>()</span> {</span><span>if</span> (is_object(<span>$this</span>-><span>list</span>)) { <span>$this</span>-><span>list</span> = <span>null</span>; } } <span>/** * 是否为空表 */</span><span>public</span><span><span>function</span><span>listEmpty</span><span>()</span> {</span><span>if</span> (is_object(<span>$this</span>-><span>list</span>)) { <span>return</span><span>$this</span>-><span>list</span>->length == <span>0</span> ? <span>true</span> : <span>false</span>; } } <span>/** * 返回元素个数 */</span><span>public</span><span><span>function</span><span>listLength</span><span>()</span> {</span><span>if</span> (is_object(<span>$this</span>-><span>list</span>)) { <span>return</span><span>$this</span>-><span>list</span>->length; } } <span>/** * 获取指定位置的元素 */</span><span>public</span><span><span>function</span><span>getElem</span><span>(<span>$i</span>)</span> {</span><span>if</span> (<span>$i</span> < <span>1</span> || <span>$i</span> > <span>$this</span>-><span>list</span>->length + <span>1</span>) { <span>return</span><span>false</span>; } <span>return</span><span>$this</span>-><span>list</span>->elem[<span>$i</span>-<span>1</span>]; } <span>/** * 在指定位置插入元素 */</span><span>public</span><span><span>function</span><span>listInsert</span><span>(<span>$i</span>, <span>$e</span>)</span> {</span><span>if</span> (<span>$i</span> < <span>1</span> || <span>$i</span> > <span>$this</span>-><span>list</span>->length + <span>1</span>) { <span>return</span><span>false</span>; } <span>if</span> (<span>$this</span>-><span>list</span>->length >= <span>$this</span>-><span>list</span>->size) { <span>$this</span>-><span>list</span>->size += <span>self</span>::LIST_INCREMENT; } <span>for</span> (<span>$j</span> = <span>$this</span>-><span>list</span>->length; <span>$j</span> >= <span>$i</span>; <span>$j</span>--) { <span>$this</span>-><span>list</span>->elem[<span>$j</span>] = <span>$this</span>-><span>list</span>->elem[<span>$j</span>-<span>1</span>]; } <span>$this</span>-><span>list</span>->elem[<span>$i</span>-<span>1</span>] = <span>$e</span>; <span>$this</span>-><span>list</span>->length++; } <span>/** * 删除指定位置数据元素 */</span><span>public</span><span><span>function</span><span>listDelete</span><span>(<span>$i</span>)</span> {</span><span>if</span> (<span>$i</span> < <span>1</span> || <span>$i</span> > <span>$this</span>-><span>list</span>->length) { <span>return</span><span>false</span>; } <span>$data</span> = <span>$this</span>-><span>list</span>->elem[<span>$i</span>-<span>1</span>]; <span>for</span> (<span>$j</span> = <span>$i</span> -<span>1</span>; <span>$j</span> < <span>$this</span>-><span>list</span>->length -<span>1</span>; <span>$j</span>++) { <span>$this</span>-><span>list</span>->elem[<span>$j</span>] = <span>$this</span>-><span>list</span>->elem[<span>$j</span>+<span>1</span>]; } <span>unset</span>(<span>$this</span>-><span>list</span>->elem[<span>$this</span>-><span>list</span>->length-<span>1</span>]); <span>$this</span>-><span>list</span>->length--; <span>return</span><span>$data</span>; } }</code>
Copyright Statement: This article is the original article of the blogger and may not be reproduced without the permission of the blogger.
The above introduces the sequential storage structure of linear tables implemented in PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

List operation //Insert a value from the head of the list. $ret=$redis->lPush('city','guangzhou');//Insert a value from the end of the list. $ret=$redis->rPush('city','guangzhou');//Get the elements in the specified range of the list. 0 represents the first element of the list, -1 represents the last element, and -2 represents the penultimate element. $ret=$redis->l

Use Java's String.length() function to get the length of a string. In Java programming, string is a very common data type. We often need to get the length of a string, that is, the number of characters in the string. In Java, we can use the length() function of the String class to get the length of a string. Here is a simple example code: publicclassStringLengthExample{publ

1: JSONArray to ListJSONArray string to List//Initialize JSONArrayJSONArrayarray=newJSONArray();array.add(0,"a");array.add(1,"b");array.add(2,"c") ;Listlist=JSONObject.parseArray(array.toJSONString(),String.class);System.out.println(list.to

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Method to convert list to numpy: 1. Use the numpy.array() function. The first parameter of the function is a list object, which can be a one-dimensional or multi-dimensional list; 2. Use the numpy.asarray() function, which will try its best to Use the data type of the input list; 3. Use the numpy.reshape() function to convert the one-dimensional list into a multi-dimensional NumPy array; 4. Use the numpy.fromiter() function, the first parameter of the function is an iterable object.
