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"
";?>