classsqlist{ Public$elem; Public$length; Public$size;} classLinear{ConstList_init_size =Ten;ConstList_increment =5;Private$list=NULL;/** * Constructs an empty linear table * / Public functioninitlist() {$this-List=NewSqList ();$this-List->elem =Array();$this-List->length =0;$this-List->size = Self:: List_init_size;returntrue; }/** * Destroy Linear table * / Public functiondestorylist() {if(Is_object ($this-List)) {$this-List=NULL; } }/** * is empty table * / Public functionlistempty() {if(Is_object ($this-List)) {return$this-List->length = =0?true:false; } }/** * Returns the number of elements * / Public functionlistlength() {if(Is_object ($this-List)) {return$this-List->length; } }/** * Gets the element at the specified position * / Public functiongetelem($i) {if($i<1||$i>$this-List->length +1) {returnfalse; }return$this-List->elem[$i-1]; }/** * Insert element at specified position * / Public functionlistinsert($i, $e) {if($i<1||$i>$this-List->length +1) {returnfalse; }if($this-List->length >=$this-List->size) {$this-List->size + = Self:: List_increment; } for($j=$this-List->length;$j>=$i;$j--) {$this-List->elem[$j] =$this-List->elem[$j-1]; }$this-List->elem[$i-1] =$e;$this-List->length++; }/** * Delete specified location data element */ Public functionlistdelete($i) {if($i<1||$i>$this-List->length) {returnfalse; }$data=$this-List->elem[$i-1]; for($j=$i-1;$j<$this-List->length-1;$j++) {$this-List->elem[$j] =$this-List->elem[$j+1]; }unset($this-List->elem[$this-List->length-1]);$this-List->length--;return$data; }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the PHP implementation of linear table sequential storage structure, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.