#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;
}
問題求解:
二叉樹的先序,中序,後序周遊的地遞歸與非遞歸的實作下載下傳: