Linear table structure: Array

     The first is to introduce a data structure array.

     Array (the Array) is a linear table data structure with a set of contiguous memory space to store a set of data having the same type.

     If you learn C language, should be very familiar with this definition, but in this dynamic PHP language, because the array by the underlying hash table (We will look at this data structure) to achieve, so incredibly powerful , this conventional array definition does not hold in PHP, PHP array can store any type of data , if compared with Java, then, PHP array integrated Java array, List, Set, Map all in one, so write code more efficient than Java the several orders of magnitude.

     Despite this dynamic PHP or JavaScript language, for conventional arrays, such as C and Java array size required before use and the type of data stored declare an array of arrays, advantages array is marked by a random value access any element within the array, the complexity of the algorithm is O (1), is very efficient, but the disadvantage is to remove / insert elements more strenuous to remove, for example, an element necessary to delete, move forward to a subsequent elements bit, if it is inserted, you need an element after the insert position are moved back, so to insert into the array / deletion, the complexity of the algorithm is O (the n-) , of course, this is for C / Java language For, PHP is not bound by this, because it is not the same thing array tradition.

 

Guess you like

Origin www.cnblogs.com/mzhaox/p/11294001.html
Recommended