正在加载图片...
int F(int m, int nt if(m>=0&&n>=0){ InitStack(S); push(S, m, n); 结 构 while( StackEmpty(S) pop(s, m, n); if (n==-1)n=result if (m*n==0)result= m+n+1 栈和队列 else push(S, m-1, -1);push(S, m, n-1):) return result; 3 3/typedef struct(int m, n; SElem Type; F函数的非递归算法 Result whie( StackEmpty(S))12条语句 第一次循环2 2,0 据pop(S,m,n) 次循环 031,-1 构if(n=1) 第三次循环1 n=result 0,-1 if(m*n==0 第四次循环 result= m+n+l; 0,-1 栈和队列 else 第五次循环1 push(S,m-1,-1); push(S, m, n-1); 第六次循环1020,-1 第七次循环「02|39 数 据 结 构 之 栈 和 队 列 17 F函数的非递归算法 int F(int m,int n){ if(m>=0 && n>=0){ InitStack(S); push(S, m , n); while(!StackEmpty(S) ){ pop(S, m , n); if (n==-1) n=result; if (m*n= =0) {result = m+n+1;} else {push(S,m-1,-1);push(S,m,n-1);} } return result; } } //typedef struct{int m,n;}SElemType; 数 据 结 构 之 栈 和 队 列 18 while(!StackEmpty(S) ) { pop(S, m , n); if(n==-1) n=result; if(m*n= =0) result = m+n+1; else { push(S,m-1,-1); push(S,m,n-1); } } 第七次循环 0 2 3 0,-1 0,-1 0,-1 0,-1 第六次循环 1 0 2 1,0 0,-1 0,-1 0,-1 第五次循环 1 1 3 1,1 0,-1 0,-1 第四次循环 1 2 3 1,2 0,-1 第三次循环 1 3 3 第二次循环 2 0 3 1,-1 2,0 1,-1 第一次循环 2 1 1,2条语句 2 1 2,1 标号 M N Result S
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有