天天看点

二叉树的先序,中序,后序遍历的地递归与非递归的实现

#include "stdafx.h"
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include"stack.h"
#include "queue.h"
#include "SeqRList.h"
typedef struct Tnode//二叉树存储结构
{
	char data;
	struct Tnode *lnode;
	struct Tnode *rnode;
}Tnode;
typedef  Tnode* type;
           

栈的定义:

typedef struct
{
	type data[50];
	int top;
}stack;
void initialstack(stack *s)
{
	s->top = 0;
}
int push(stack *s, type x)
{
	if (s->top == 50)
		return -1;
	s->data[s->top++] = x;
	return 0;
}
type pop(stack *s)
{
	if (s->top == 0)
		exit(-2);
	type x = s->data[--s->top];
	return x;
}
bool isemty(stack *s)
{
	if (s->top == 0)
		return true;
	else
		return false;
}
           

问题求解:

二叉树的先序,中序,后序遍历的地递归与非递归的实现下载: