正在加载图片...
push(s, a,b )) i//while while(Stack Empty(s)) pop(s, t); *=t i/while return OK i//F nonrecursive float Sqrt recursive (float A, float p, float e)求平方根的递归算法 if(abs(p 2-Ak=e)return p: else return sqrt recurve(A, (p+A/p)/2, e); float Sqrt nonrecursive(float A, float p, float e求平方根的非递归算法 while(abs(p 2-Ap=e) p=(p+A/p)2 return p, nonrecursive 3.27 这一题的所有算法以及栈的变化过程请参见《数据结构 (pascal版)》,作者不再详 细写出 3.28 void Init CiQueue( CiQueue&Q∥初始化循环链表表示的队列Q Q=(CiLNode")malloc(sizeof(CILNode)) //nit CiQueue void EnCiQueue( CiQueue&Q,intx)/把元素ⅹ插入循环链表表示的队列QQ指向 队尾元素,Q->next指向头结点,Q->next>next指向队头元素{ 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 void EnCiQueue(CiQueue &Q,int x)//把元素 x 插入循环链表表示的队列 Q,Q 指向 队尾元素,Q->next 指向头结点,Q->next->next 指向队头元素
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有