色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

PHP 數據結構 算法 三元組 Triplet

復制代碼 代碼如下:
<?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 < 1 || $key > 3) return false;
return $this->_data[$key - 1];
}
// 設置第$key元的值為$val
public function put($key,$val)
{
if($key < 1 || $key > 3) return false;
$this->_data[$key - 1] = $val;
return true;
}
// 是否按升序排序
public function isAscending()
{
return ($this->_data[0] <= $this->_data[1]) && ($this->_data[1] <= $this->_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] <= $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 "<br/>";
echo "get 1:";var_dump($objTriplet->get(1)); echo "<br/>";
echo "get 4:";var_dump($objTriplet->get(4)); echo "<br/>"; // false
echo "put 3,4:";var_dump($objTriplet->put(3,4)); echo "<br/>";
echo "max:";var_dump($objTriplet->max()); echo "<br/>";
echo "min:";var_dump($objTriplet->min()); echo "<br/>";
echo "isAscending:";var_dump($objTriplet->isAscending()); echo "<br/>";
echo "isDescending:";var_dump($objTriplet->isDescending()); echo "<br/>";
?>

php技術PHP 數據結構 算法 三元組 Triplet,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 怀来县| 东乌珠穆沁旗| 扬州市| 茌平县| 大悟县| 阳高县| 卫辉市| 馆陶县| 定南县| 九龙坡区| 贵南县| 桦甸市| 临汾市| 石泉县| 安福县| 裕民县| 当雄县| 阳朔县| 白山市| 三门峡市| 泗洪县| 丰都县| 肇州县| 政和县| 扎囊县| 白玉县| 库车县| 苏尼特左旗| 攀枝花市| 贵阳市| 南木林县| 北辰区| 区。| 田阳县| 荥阳市| 安多县| 余干县| 庆城县| 枞阳县| 德江县| 宽甸|