⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cre_pre.cpp

📁 文件夹中包括常用的数据结构的算法
💻 CPP
字号:
#include<malloc.h>
#include <stdio.h>
#define m0 100
#define m2 20
#define null 0
#define Len  sizeof (BinNode)

enum tag{zero,one};

typedef struct BinNode             // 结点结构
{ 
	char data;
    struct BinNode *lch,*rch;
    enum tag ltag,rtag;
}BinNode,*Bintree;


struct chtp{ int len;      char ch[m0];    };
struct BinNode *bt,*m,*stack[m2];
struct chtp s;
int top=0,ii=0;

void  crt_pre(Bintree *t) 
{ 
	char c;      
//	int i;
    c=s.ch[ii];  
	ii=ii+1;

    if (c=='.')  *t=null;
    else 
	{ 
		*t=(BinNode *)malloc(Len);
		(*t)->data=c;
		crt_pre(&(*t)->lch);
		crt_pre(&(*t)->rch);
    };
}

void inorder1( BinNode *t)      /*中序遍历二叉树的非递归算法*/
{
	BinNode *p;
    top=0;stack[top]=t;
    while (top!=-1)
    { 
		for(;stack[top]!=null;)
		{ 
			top=top+1;
			stack[top]=stack[top-1]->lch;  
		};
        top=top-1;
        if(top!=-1) 
        {
			p=stack[top];
			printf("%c",(*p).data);      
            stack[top]=(*p).rch;  
		};
     }
}


void main()
{
//	char /*c[]={'a','b','d','.','.','.','c','e','.','.','f','.','.','!'};*/
    char    c[]={'a','b','c','.','.','d','e','.','g','.','.','f','.','.','.','!'};
    int i=0,num;
    for(i=0,s.len=0;c[i]!='!';i++,s.len++) s.ch[i]=c[i];
    
	crt_pre(&bt);
	
	inorder1(bt);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -