Copy CodeThe code is as follows:
/**
* Ternary Group Triplet
*
*/
Class Triplet
{
Private $_data = null;
Initialize ternary groups
Public Function init ($val 1, $val 2, $val 3)
{
$this->_data[0] = $val 1;
$this->_data[1] = $val 2;
$this->_data[2] = $val 3;
return true;
}
Destroying ternary groups
Public function Destroy ()
{
unset ($this->_data);
return true;
}
Returns the value of section $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 true;
}
Whether to sort in ascending order
Public Function isascending ()
{
Return ($this->_data[0] <= $this->_data[1]) && ($this->_data[1] <= $this->_data[2]);
}
Whether to sort by descending
Public Function isdescending ()
{
Return ($this->_data[0] >= $this->_data[1]) && ($this->_data[1] >= $this->_data[2]);
}
Get maximum Value
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];
}
Get Minimum value
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); 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 "
";
?>
The above describes the trading places PHP data structure algorithm ternary group Triplet, including the trading places aspects of the content, I hope that the PHP tutorial interested in a friend helpful.