正在加载图片...
pop(s, b) c=link(link(*p, b), a); push(s, c) i/else p++; i/while pop(s, new) if(!Stack Empty(s))return ERROR; return OK i/NiBoLan to BoLan 分析基本思想见书后注释本题中暂不考虑串的具体操作的实现而将其看作 种抽象数据类型 stringtype,对其可以进行连接操作c=link(ab) 3.24 Status g(int m,intn,int&sy/求递归函数g的值s if(m=0&&n>=0)s=0 else if(m>0&&n>=0)s=n+g(m-1,2*n); else return erROR: turn oK }/g 3.25 Status F recursive(int n, int&s∥/递归算法 if(n<0)return ERROR if(n==0)s=n+1; else F recurve(n/2, r); s=n*r return OK cursive Status f nonrecursive( int n int s/非递归算法 if(n<o) return ERROR if(n==0)s=n+1; InitStack(s,/s的元素类型为 struct{ int a int b;} while(nl=0)pop(s,b); c=link(link(*p,b),a); push(s,c); }//else p++; }//while pop(s,new); if(!StackEmpty(s)) return ERROR; return OK; }//NiBoLan_to_BoLan 分析:基本思想见书后注释.本题中暂不考虑串的具体操作的实现,而将其看作一 种抽象数据类型 stringtype,对其可以进行连接操作:c=link(a,b). 3.24 Status g(int m,int n,int &s)//求递归函数 g 的值 s { if(m==0&&n>=0) s=0; else if(m>0&&n>=0) s=n+g(m-1,2*n); else return ERROR; return OK; }//g 3.25 Status F_recursive(int n,int &s)//递归算法 { if(n<0) return ERROR; if(n==0) s=n+1; else { F_recurve(n/2,r); s=n*r; } return OK; }//F_recursive Status F_nonrecursive(int n,int s)//非递归算法 { if(n<0) return ERROR; if(n==0) s=n+1; else { InitStack(s); //s 的元素类型为 struct {int a;int b;} while(n!=0)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有