insert.c

来自「Trees are natural structures for represe」· C语言 代码 · 共 22 行

C
22
字号
#include <stdio.h>#include "Tree.h"void insertTree( TreeElementType E, Tree *T )/*  pre: T is a binary search tree *//* post: E is in T and T is still a binary search tree *//* NB. T is a reference parameter and the tree is changed as a side-effect */ { if( *T == NULL )    { *T = (Tree)malloc(sizeof(Node)); /*new leaf*/      (*T)->left = (*T)->right = (Tree)NULL;                  /*L*/      TreeElementMove(E, &((*T)->elt));                       /*.*/    }                                                         /*A*/   else/*T not NULL*/                                         /*l*/      if( TreeElementLess( E, (*T)->elt) )                    /*l*/         insertTree( E, &((*T)->left) );                      /*i*/      else if( TreeElementLess((*T)->elt, E) )                /*s*/         insertTree( E, &((*T)->right) );                     /*o*/   /* else  equal, in this implementation do nothing */       /*n*/ }/*insertTree*//* Insert a New Element E into a Binary Search Tree T. */

⌨️ 快捷键说明

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