热门关键字:  ubuntu  分区  Fedora  linux系统进程  函数

当前位置 :| 主页>Linux教程>编程开发>PHP>

我就给一个PHP逆波兰表达式的算法吧---工资计算专用

来源: 作者: 时间:2008-05-16 Tag: 点击:


} elseif ($temp=='(') {
$this->_stackAdd($temp);
} elseif (($this->_stackEmpty()) || (($this->_priority($temp) > $this->_stackPriority()))) {
$this-> _stackAdd($temp);
} else {
while(!$this->_stackEmpty() && ($this->_priority($temp) <= $this->_stackPriority())) {
$this->_outputAdd($this->_stackDelete());
}
$this->_stackAdd($temp);
}

}

}

while(!$this->_stackEmpty()) {
$this->_outputAdd($this->_stackDelete());
}

return $this->_output;
}



function _rpnToValue() {

$time1 = $this->_getMicroTime();

if ($this->_error <> null) {
$this->_value = null;
return $this->_value;
}

$this->_value = 0;
$temp = $this->_output;

do {
$pos = $this->_nextOperator($temp);

if ($pos == -1) {
$this->_error = $this->_raiseError('Syntax error');
$this->_value = null;
return $this->_value;
}

$operator = $this->_operation[$temp[$pos]];
$arg = $operator[2];
$function = $operator[3];

if (($arg==2) && (!isset($temp[$pos-1]) || !is_numeric($temp[$pos-1]) || !isset($temp[$pos-2]) || !is_numeric($temp[$pos-2]))) {
$this->_error = $this->_raiseError('Syntax error');
$this->_value = null;
return $this->_value;
} elseif (($arg==1) && (!isset($temp[$pos-1]) || !is_numeric($temp[$pos-1]))) {
$this->_error = $this->_raiseError('Syntax error');
$this->_value = null;
return $this->_value;
}

if(is_array($function)) {

if($arg==2) $arg_array = array($temp[$pos-2],$temp[$pos-1]);
elseif($arg==1) $arg_array = array($temp[$pos-1]);
else $arg_array = array();

if($function['type'] == 'userFunction') {
$this->_value = call_user_func_array($function['function'], $arg_array);
} else {
$function_array = array(&$function['class'], $function['method']);
$this->_value = call_user_func_array($function_array, $arg_array);
}
} else {
$this->_value = $this->$function($temp, $pos);
}

if ($this->_isNan($this->_value)) {
$this->_error = $this->_raiseError('NAN value');
$this->_value = null;
return $this->_value;
} elseif ($this->_isInfinite($this->_value)) {
$this->_error = $this->_raiseError('Infinite value');
$this->_value = null;
return $this->_value;
} elseif (is_null($this->_value)) {
return $this->_value;
}

$temp = $this->_refresh($temp, $pos, $arg, $this->_value);
} while(count($temp) > 1);

$this->_value = $temp[0];

$time2 = $this->_getMicroTime();

$this->_timer = $time2 - $time1;

return $this->_value;
}

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
栏目列表