正在加载图片...
Init Stack(s),/s的元素类型为 struct{inta;intb;} hile(n=0) an bush(s, (a,b)); i/while while(stack Empty(s)) pop(s, t) s*气ta; i//while return OK 3//F nonrecursive 3.26 float Sqrt recursive(float A, float p, float e求平方根的递归算法 if(abs(p 2-A)=e)return else return sqrt recurve(A, (p+ A/p)2, e) i//Sqrt recurve float Sqrt nonrecursive(float A, float p, float ey/求平方根的非递归算法 while(abs(p 2-Ap=e) (p+A/p)2 i/ Sqrt nonrecursive 这一题的所有算法以及栈的变化过程请参见《数据结构 (pascal版)》,作者不再详 细写出 void Init CiQueue( CiQueue&Q初始化循环链表表示的队列Q Q=(CiLNode *)malloc(sizeof(CILNode)) Q i//nitCiQueue{ InitStack(s); //s 的元素类型为 struct {int a;int b;} while(n!=0) { a=n;b=n/2; push(s,{a,b}); n=b; }//while s=1; while(!StackEmpty(s)) { pop(s,t); s*=t.a; }//while } return OK; }//F_nonrecursive 3.26 float Sqrt_recursive(float A,float p,float e)//求平方根的递归算法 { if(abs(p^2-A)<=e) return p; else return sqrt_recurve(A,(p+A/p)/2,e); }//Sqrt_recurve float Sqrt_nonrecursive(float A,float p,float e)//求平方根的非递归算法 { while(abs(p^2-A)>=e) p=(p+A/p)/2; return p; }//Sqrt_nonrecursive 3.27 这一题的所有算法以及栈的变化过程请参见《数据结构(pascal 版)》,作者不再详 细写出. 3.28 void InitCiQueue(CiQueue &Q)//初始化循环链表表示的队列 Q { Q=(CiLNode*)malloc(sizeof(CiLNode)); Q->next=Q; }//InitCiQueue
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有