由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 怎样记数多次递归调用种某项操作的次数?
相关主题
Comparison Re: 组合的枚举算法?为毛本版就整天争论语言呢。。。
An algorithm question.Performance Comparison Between Node.js and Java EE
C++ question请教一个C++ typedef的问题
[合集] image processing & comparison questions怎么学习python的函数里面调用函数本身(函数递归)?
Efficient algorithms for finding number, help pleasefree code comparison software
请教一下text comparison software.Why PostgreSQL is way BETTER than $MSQL
弱问内存的问题急,VC7.1编译错误
DW BI ETL 问题 - Data Validation and Recordset Comparisonvector的析构问题
相关话题的讨论汇总
话题: int话题: vector话题: 递归函数话题: 次数话题: 数组
进入Programming版参与讨论
1 (共1页)
t**********s
发帖数: 930
1
比如下面这个同时求出一个数组中最大和最小值的算法,我已算出其元素之间的比较次
数是3n/2-2,这要比分别扫描数组两次所比较次数2*(n-1)要少。
我的问题是如何让这个递归函数自己记下算出递归的次数?
我对递归函数间如何传递数据很糊涂。
vector minmax( vector V, int l, int u )
{
int m;
vector M( 2 ), M1( 2 ), M2( 2 );

if( u == l ) // one element - no comparisons needed
{
M[0] = V[l]; M[1] = V[u];
return M;
}
if( u-l == 1 ) // two elements - only one comparison
{
if( V[l] <= V[u] )
{
M[0] = V[l]; M[1] = V[u];
g*****g
发帖数: 34805
2
传个引用参数进去,跟使全局变量一个效果。

【在 t**********s 的大作中提到】
: 比如下面这个同时求出一个数组中最大和最小值的算法,我已算出其元素之间的比较次
: 数是3n/2-2,这要比分别扫描数组两次所比较次数2*(n-1)要少。
: 我的问题是如何让这个递归函数自己记下算出递归的次数?
: 我对递归函数间如何传递数据很糊涂。
: vector minmax( vector V, int l, int u )
: {
: int m;
: vector M( 2 ), M1( 2 ), M2( 2 );
:
: if( u == l ) // one element - no comparisons needed

t**********s
发帖数: 930
3
I got it myself. Just increase the vector size to 3 with the third one
holding the number of comparison.

【在 g*****g 的大作中提到】
: 传个引用参数进去,跟使全局变量一个效果。
1 (共1页)
进入Programming版参与讨论
相关主题
vector的析构问题Efficient algorithms for finding number, help please
C++请教,使用c++ vector iterator后输出vector数据出错请教一下text comparison software.
Remove elements from multiple vectors in C++弱问内存的问题
能帮我看看Ruby的这道题吗?DW BI ETL 问题 - Data Validation and Recordset Comparison
Comparison Re: 组合的枚举算法?为毛本版就整天争论语言呢。。。
An algorithm question.Performance Comparison Between Node.js and Java EE
C++ question请教一个C++ typedef的问题
[合集] image processing & comparison questions怎么学习python的函数里面调用函数本身(函数递归)?
相关话题的讨论汇总
话题: int话题: vector话题: 递归函数话题: 次数话题: 数组