首页 > 其他 > 详细

非递归交换二叉树左右子树

时间:2016-02-08 17:23:25      阅读:294      评论:0      收藏:0      [点我收藏+]
 1 void exchange( struct node* node){  
 2     struct node* tnode = node;  
 3     struct node* tmp = NULL;  
 4   
 5     if(node == NULL)  
 6         return;  
 7   
 8     while(1){  
 9         tmp = tnode-> left;  
10         tnode-> left = tnode->right ;  
11         tnode-> right = tmp;  
12   
13         if(tnode->right ){  
14             push(tnode-> right);  
15         }  
16   
17         if(tnode->left ){  
18             tnode = tnode->left;  
19         }  
20         else{  
21             if(!empty()){  
22                 tnode = top();  
23                 pop();  
24             }  
25             else{  
26                 break;  
27             }  
28         }  
29     }  
30 }

 

非递归交换二叉树左右子树

原文:http://www.cnblogs.com/zpfcode/p/5185052.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!