↖(^ω^)↗
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 }