↖(^ω^)↗

 1 /*
 2 
 3 编写算法函数void preorder1(bintree t)实现二叉树t的非递归前序遍历。
 4 
 5 */
 6 
 7 #include "bintree.h"
 8 char *a="ABC##D#E##F##";  /*扩充二叉树序树t的前序序列*/
 9 
10 /*函数preorder1()的功能是非递归前序遍历二叉树t,请将函数补充完整并调试运行*/
11 void preorder1(bintree t)
12 {
13     bintree p = t;
14 
15     seqstack s;
16     init(&s);
17     while(p!=NULL||!empty(&s))
18     {
19 
20         while(p!=NULL)
21         {
22             printf("%c",p->data);
23             push(&s,p);
24             p = p->lchild;
25         }
26 
27         if(!empty(&s))
28         {
29             p=pop(&s);
30             p=p->rchild;
31         }
32     }
33 }
34 
35 int main()
36 {
37     bintree t;
38     t=creatbintree();   /*建立二叉树t的存储结构*/
39     printf("二叉树的前序序列为:\n");
40     //preorder(t);
41     preorder1(t);       /*前序非递归遍历二叉树*/
42     return 0;
43 }
实现二叉树t的非递归前序遍历

相关文章:

  • 2021-11-15
  • 2021-05-16
  • 2021-08-21
  • 2021-06-13
  • 2021-11-01
  • 2021-08-19
  • 2022-03-02
猜你喜欢
  • 2022-12-23
  • 2021-11-20
  • 2021-06-03
  • 2021-11-22
  • 2021-07-30
  • 2021-08-13
  • 2021-08-18
相关资源
相似解决方案