Php ordered linear table

Source: Internet
Author: User
Php ordered linear table
 SeqArr = $ arr; $ this-> length = count ($ arr);}/** returns the $ index data element in the linear table */public function GetElem ($ index) {if ($ this-> length) = 0 | $ index <0 | ($ index> $ this-> length) {return "Error ";} return $ this-> seqArr [$ index-1];}/** returns the length of the linear table **/public function ListLength () {return $ this-> length ;} /** return the location of the given data element in the linear table */public function LocateElem ($ elem) {for ($ I = 0; $ I <($ this-> length ); $ I ++) {if ($ this-> seqArr [$ I]) ==$ elem) {return $ I + 1 ;}}/ ** PriorElem: returns the first element of the specified element */public function PriorElem ($ elem) {for ($ I = 0; $ I <($ this-> length); $ I ++) {if ($ this-> seqArr [$ I]) ==$ elem) {if ($ I = 0) {return "Error (is null )";} else {return $ this-> seqArr [$ I-1] ;}}}/** NextElem: returns the last element of the specified element */public function NextElem ($ elem) {for ($ I = 0; $ I <($ this-> length ); $ I ++) {if ($ this-> seqArr [$ I]) = $ elem) {return $ this-> seqArr [$ I + 1] ;}}/ ** ListInsert: Insert the element elem */public function ListInsert ($ index, $ elem) {if ($ this-> length) = 0 | $ index <0 | $ index> ($ this-> length )) {return "Error" ;}for ($ I = $ index; $ I <($ this-> length); $ I ++) {$ this-> seqArr [$ I + 1] = $ this-> seqArr [$ I] ;}$ this-> seqArr [$ index] = $ elem; $ this-> length = $ this-> l Ength + 1; return $ this-> seqArr;}/** ListDelete: delete the element at the index */public function ListDelete ($ index) {if ($ this-> length) = 0 | $ index <0 | $ index> ($ this-> length-1 )) {return "Error";} unset ($ this-> seqArr [$ index]); array_values ($ this-> seqArr); return $ this-> seqArr ;}}?>

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.