7-4.c

来自「本人收集的一些数据结构经典算法实现」· C语言 代码 · 共 34 行

C
34
字号
#include "stdio.h"
typedef char Datatype;
typedef struct threaded_tree *pt_threaded;
typedef struct threaded_tree {
	short  int  left_thread;
    pt_threaded left_child;  
    Datatype  data;
    pt_threaded right_child;
    short  int  right_thread;
};
pt_threaded succ( pt_threaded tree)
{ //在树中找到结点的中序前驱
   pt_threaded temp;
   temp = tree->right_child;
   if ( !tree->right_thread )
	while( !temp->left_child )
		temp = temp->left_child;
   return temp;
}
void inorder(pt_threaded tree)
{   //中序遍历线索二叉树
   pt_threaded temp=tree;
   for(; ;){
	temp = succ (temp);
	if (temp = tree) break;
	printf ("%3c", temp->data);
   }
}

void main()
{
	pt_threaded p;
	inorder(p);
}

⌨️ 快捷键说明

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