Data Structure & algorithm (PHP description) triple Triplet-PHP source code

Source: Internet
Author: User
Data Structure & amp; Algorithm (PHP description) triple Triplet PHP Data structure algorithm triple Triplet. For more information about learning php, see.

 _ Data [0] = $ val1; $ this-> _ data [1] = $ val2; $ this-> _ data [2] = $ val3; return true ;} // destroy the triple public function destroy () {unset ($ this-> _ data); return true;} // return the value of $ key public function get ($ key) {if ($ key <1 | $ key> 3) return false; return $ this-> _ data [$ key-1];} // set the value of $ key to $ val public function put ($ key, $ val) {if ($ key <1 | $ key> 3) return false; $ this-> _ data [$ key-1] = $ val; return tru E;} // whether to sort public function isAscending () {return ($ this-> _ data [0] <= $ this-> _ data [1]) in ascending order & ($ this-> _ data [1] <= $ this-> _ data [2]);} // whether to sort public function isDescending () in descending order () {return ($ this-> _ data [0] >=$ this-> _ data [1]) & ($ this-> _ data [1] >=$ this-> _ data [2]);} // obtain the maximum value of public function max () {return ($ this-> _ data [0] >=$ this-> _ data [1])? ($ This-> _ data [0] >=$ this-> _ data [2])? $ This-> _ data [0]: $ this-> _ data [2]: ($ this-> _ data [1] >=$ this-> _ data [2])? $ This-> _ data [1]: $ this-> _ data [2];} // obtain the minimum public function min () {return ($ this-> _ data [0] <= $ this-> _ data [1])? ($ This-> _ data [0] <= $ this-> _ data [2])? $ This-> _ data [0]: $ this-> _ data [2]: ($ this-> _ data [1] <= $ this-> _ data [2])? $ This-> _ data [1]: $ this-> _ data [2] ;}// $ objTriplet = new Triplet (); echo "init :"; var_dump ($ objTriplet-> init (1, 2, 3); echo"
"; Echo" get 1: "; var_dump ($ objTriplet-> get (1); echo"
"; Echo" get 4: "; var_dump ($ objTriplet-> get (4); echo"
"; // False echo" put 3, 4: "; var_dump ($ objTriplet-> put (3, 4); echo"
"; Echo" max: "; var_dump ($ objTriplet-> max (); echo"
"; Echo" min: "; var_dump ($ objTriplet-> min (); echo"
"; Echo" isAscending: "; var_dump ($ objTriplet-> isAscending (); echo"
"; Echo" isDescending: "; var_dump ($ objTriplet-> isDescending (); echo"
";?>

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.