7-5.c

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

C
38
字号
#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 right_insert(pt_threaded parent,pt_threaded child)
{  //在线索二叉树中插入结点,使之成为父结点的右孩子*/   
	pt_threaded temp;
    child->right_child=parent->right_child;
    child->right_thread=parent->right_thread;
    child->left_child=parent;
    child->left_thread=1;
    parent->right_child=child;
    parent->right_thread=0;
    if ( !child->right_thread ) {
	  temp = succ(child);
	  temp->left_child = child;
    }
}
void main()
{
	pt_threaded p,c;
	right_insert(p,c);
}

⌨️ 快捷键说明

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