最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP 數(shù)據(jù)結(jié)構(gòu) 算法 三元組 Triplet

 更新時(shí)間:2011年07月02日 23:56:29   作者:  
PHP 數(shù)據(jù)結(jié)構(gòu) 算法 三元組 Triplet,學(xué)習(xí)php的朋友可以參考下。
復(fù)制代碼 代碼如下:

<?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];
}
// 設(shè)置第$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/>";
?>

相關(guān)文章

最新評(píng)論

珲春市| 宣汉县| 武宁县| 台北县| 虎林市| 孙吴县| 偏关县| 台南县| 资中县| 九龙坡区| 沿河| 札达县| 普兰县| 海阳市| 应用必备| 金沙县| 安溪县| 巴林左旗| 襄汾县| 靖西县| 奉化市| 偃师市| 安阳市| 葵青区| 浏阳市| 蒲城县| 长兴县| 宝丰县| 宁明县| 尼勒克县| 德清县| 博白县| 敦煌市| 宁国市| 通江县| 尼勒克县| 乌拉特中旗| 根河市| 宜黄县| 永川市| 南雄市|