當前位置:編程學習大全網 - 源碼下載 - c語言樹源代碼

c語言樹源代碼

#包含“stdio.h”

#包含" stdlib.h "

#包含“conio.h”

#ifndef NULL

#定義NULL 0

#endif

typedef結構節點

{

字符值;

結構節點*pL,* pR

}節點,* pNode

pNode pH

void DeleteBinaryTree(pNode pNode)

{

if ( pNode == NULL)

返回;

if(pNode-& gt;pL!=空)

DeleteBinaryTree(pNode-& gt;pL);

if(pNode-& gt;公關!=空)

DeleteBinaryTree(pNode-& gt;pR);

免費(pNode);

}

void CreateBinaryTree(pNode * PP head)

{

char ch

if ( NULL!= *ppHead)

DeleteBinaryTree(* PP head);

ch = getch();

putch(ch);

if ( ch == ' ')

{

* ppHead = NULL

返回;

}

* PP head =(pNode)malloc(sizeof(node));

(* ppHead)-& gt;value = ch

(* ppHead)-& gt;pL = NULL

(* ppHead)-& gt;pR = NULL

CreateBinaryTree(& amp;(* ppHead)-& gt;pL);

CreateBinaryTree(& amp;(* ppHead)-& gt;pR);

返回;

}

void VisitBinaryTree ( pNode pHead,void (*VisitNode)(char),int order)

{

if ( pHead == NULL)

返回;

if ( order == 1)

(* visit node)(pHead-& gt;值);

visit binary tree(pHead-& gt;pL,VisitNode,order);

if ( order == 2)

(* visit node)(pHead-& gt;值);

visit binary tree(pHead-& gt;pR,VisitNode,order);

if ( order == 3)

(* visit node)(pHead-& gt;值);

}

作廢打印(char ch)

{

printf ( "%c ",ch);

}

void main()

{

printf("請輸入:\ n ");

CreateBinaryTree(& amp;pH);

printf(" \ n \ n結果:\ n ");

VisitBinaryTree ( pH,Print,1);

putch(' \ n ');

VisitBinaryTree ( pH,Print,2);

putch(' \ n ');

VisitBinaryTree ( pH,Print,3);

putch(' \ n ');

DeleteBinaryTree(pH);

}

  • 上一篇:打壹個人手機(聯通打聯通),總是提示對方開通漏話提醒,短信也是發送失敗,請問是否有可能將我拉黑?
  • 下一篇:為什麽要用Visual Studio寫Python代碼
  • copyright 2024編程學習大全網