版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、中序遍歷非遞歸算法演示int NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraver
2、se中序遍歷二叉樹非遞歸算法棧的變化 A SABDCFEGint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return O
3、K; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A SABDCFEGint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild
4、); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A BSABDCFEGint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERR
5、OR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A C BSABDCFEGint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!vis
6、it(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A C BSABDCFEGint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) P
7、op(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A C BSABDCFEGint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退
8、棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A C BSABDCFEGint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);
9、/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A BSABDCFEGint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p
10、) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A BSABDCFEGCint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下
11、 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A BSABDCFEGCint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!St
12、ackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A BSABDCFEGCint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S
13、,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A BSABDCFEGCint NInorderTraverse(BiTree &T,int(*visit)(char e)
14、InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A BSABDCFEGCint NInorderTraverse(BiTree &T,
15、int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A BSABDCFEGCint NInorde
16、rTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A S
17、ABDCFEGCint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中
18、序遍歷二叉樹非遞歸算法棧的變化 A SABDCFEGCBint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK
19、; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A DSABDCFEGCBint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchi
20、ld); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A DSABDCFEGCBint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return
21、 ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A E DSABDCFEGCBint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 i
22、f(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A E DSABDCFEGCBint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEm
23、pty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A E DSABDCFEGCBint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(
24、S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A E DSABDCFEGCBint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(
25、S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A DSABDCFEGCBint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while
26、(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A DSABDCFEGCBEint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackE
27、mpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A G DSABDCFEGCBEint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S
28、,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A G DSABDCFEGCBEint NInorderTraverse(BiTree &T,int(*visit)(char
29、 e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A G DSABDCFEGCBEint NInorderTraverse(Bi
30、Tree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A G DSABDCFEGCB
31、Eint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非
32、遞歸算法棧的變化 A G DSABDCFEGCBEint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /
33、NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A DSABDCFEGCBEint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild
34、); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A DSABDCFEGCBEGint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return
35、 ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A DSABDCFEGCBEGint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 i
36、f(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A DSABDCFEGCBEGint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEm
37、pty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A DSABDCFEGCBEGint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(
38、S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A DSABDCFEGCBEGint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(
39、S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A DSABDCFEGCBEGint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 whi
40、le(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A SABDCFEGCBEGint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!Stac
41、kEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A SABDCFEGCBEGDint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(
42、S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A FSABDCFEGCBEGDint NInorderTraverse(BiTree &T,int(*visit)(cha
43、r e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A FSABDCFEGCBEGDint NInorderTraverse(B
44、iTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A FSABDCFEGCBE
45、GDint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹
46、非遞歸算法棧的變化 A FSABDCFEGCBEGDint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK;
47、/NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A FSABDCFEGCBEGDint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rch
48、ild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A SABDCFEGCBEGDint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) ret
49、urn ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A SABDCFEGCBEGDFint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素
50、出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A SABDCFEGCBEGDFint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!St
51、ackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A SABDCFEGCBEGDFint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到
52、頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A SABDCFEGCBEGDFint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p
53、) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A SABDCFEGCBEGDFint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空
54、的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 A SABDCFEGCBEGDFint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Push(S,T);/根指針入棧 w
55、hile(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 SABDCFEGCBEGDFint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(
56、S); Push(S,T);/根指針入棧 while(!StackEmpty(S)/在樹不空的情況下 while(GetTop(S,p)&p) Push(S,p-lchild);/向左走到頭 Pop(S,p);/空指針退棧 if(!StackEmpty(S) Pop(S,p);/元素出棧 if(!visit(p-data) return ERROR; Push(S,p-rchild); /右子樹入棧 return OK; /NInOrderTraverse中序遍歷二叉樹非遞歸算法棧的變化 SABDCFEGCBEGDFAint NInorderTraverse(BiTree &T,int(*visit)(char e) InitStack(S); Pus
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2026年及未來5年中國閥體行業(yè)發(fā)展前景預(yù)測及投資戰(zhàn)略研究報(bào)告
- 職業(yè)能力培訓(xùn)成效保障承諾書(3篇)
- 2026及未來5年中國康養(yǎng)地產(chǎn)行業(yè)市場運(yùn)行格局及前景戰(zhàn)略研判報(bào)告
- 2026年及未來5年中國丙肝藥物行業(yè)市場深度分析及發(fā)展前景預(yù)測報(bào)告
- 2026年及未來5年中國機(jī)器人減速器市場前景預(yù)測及投資規(guī)劃研究報(bào)告
- 2026及未來5年中國3D生物打印行業(yè)市場行情監(jiān)測及投資前景研判報(bào)告
- 醫(yī)院標(biāo)示管理制度規(guī)范
- 緊急集散點(diǎn)規(guī)范管理制度
- 科室備用藥存放制度規(guī)范
- 規(guī)范化建設(shè)責(zé)任落實(shí)制度
- 北京市租賃房屋治安責(zé)任書
- 2026年北京市公務(wù)員錄用考試申論試題及答案
- 醫(yī)院門診部2025年度工作總結(jié)及2026年工作計(jì)劃
- 2025年醫(yī)院停電應(yīng)急預(yù)案演練腳本
- AI在醫(yī)療質(zhì)量控制中的指標(biāo)優(yōu)化
- 2、公安檢查站治安管控系統(tǒng)解決方案
- 停車場電車起火應(yīng)急預(yù)案
- 水庫清淤工程可行性研究報(bào)告
- THBFIA 0004-2020 紅棗制品標(biāo)準(zhǔn)
- GB/T 25630-2010透平壓縮機(jī)性能試驗(yàn)規(guī)程
- GB/T 19610-2004卷煙通風(fēng)的測定定義和測量原理
評(píng)論
0/150
提交評(píng)論