宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

复制代码 代码如下:
<?php
/**
* 三元组 Triplet
*
*/
class Triplet
{
private $_data = null;
// 初始化三元组
public function init$val1,$val2,$val3)
{
$this->_data[0] = $val1;
$this->_data[1] = $val2;
$this->_data[2] = $val3;
return true;
}
// 销毁三元组
public function destroy)
{
unset$this->_data);
return true;
}
// 返回第$key的值
public function get$key)
{
if$key 3) return false;
return $this->_data[$key – 1];
}
// 设置第$key元的值为$val
public function put$key,$val)
{
if$key 3) return false;
$this->_data[$key – 1] = $val;
return true;
}
// 是否按升序排序
public function isAscending)
{
return $this->_data[0] _data[1]) && $this->_data[1] _data[2]);
}
// 是否按降序排序
public function isDescending)
{
return $this->_data[0] >= $this->_data[1]) && $this->_data[1] >= $this->_data[2]);
}
// 获取最大值
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];
}
// 获取最小值
public function min)
{
return $this->_data[0] _data[1])? $this->_data[0] _data[2])? $this->_data[0] : $this->_data[2] : $this->_data[1] _data[2])? $this->_data[1] : $this->_data[2];
}
}
//
$objTriplet = new Triplet);
echo “init:”;var_dump$objTriplet->init1,2,3)); echo “
“;
echo “get 1:”;var_dump$objTriplet->get1)); echo “
“;
echo “get 4:”;var_dump$objTriplet->get4)); echo “
“; // false
echo “put 3,4:”;var_dump$objTriplet->put3,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 “
“;
?>