后序遍历的非递归算法

void PosOrder(BT *bt) { int i = 0, a[MaxSize]; BT *s[MaxSize], *p; while (p != NULL || i != 0) { while (p != NULL) { s[++i] = p; a[i] = 0; p = p->Lchild; } if (i > 0) { if (a[i] == 0) { p = s[i]; if (i > 0) { p = p->Rchild; a[...

中序遍历的非递归算法

#define MaxSize 100 typedef struct BTree { int data; struct BTree *Lchild; struct BTree *Rchild; }BT; void inorder(BT *bt) { int i = 0; BT *s[MaxSize], *p; p = bt; do { while (p != NULL) { s[i++] = p; p = p->Lchild; } if (i>0) { p = s[i--]; pri...
浏览21780次
最新评论