gpt4 book ai didi

PHP 数据结构 算法 三元组 Triplet

转载 作者:qq735679552 更新时间:2022-09-29 22:32:09 26 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章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 数据结构 算法 三元组 Triplet的文章就讲到这里了,如果你想了解更多关于PHP 数据结构 算法 三元组 Triplet的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com