正在加载图片...
if (top<=0) return, else t=stack[top tt*2+1 return: 17在二叉树中查找值为x的结点,试设计打印值为x的结点的所有祖先结点算法 void printnode bitree t, datatype x init Stack(s) while(pll Empty Stack(s)) while(p) if(p->data==x) while(! empty Stack(s) pop(s, q); cout<<q->data<<endl return: Push(s, p) p=p->lchildt=t*2; } if (top<=0) return; else { top--; t=stack[top]; t=t*2+1; } } return; } ⒘在二叉树中查找值为 x 的结点,试设计打印值为 x 的结点的所有祖先结点算法。 void printnode (BiTree t, datatype x) { init_Stack(s); p=t; while (p|| !Empty_Stack(s)) { while (p) { if (p->data= =x) { while (!Empty_Stack(s)) { pop(s,q); cout<<q->data<<endl; } return; } else { Push(s,p); } p=p->lchild;
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有