In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "how to use recursion to achieve clue binary tree in C language", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article, let's take a look at this "C language how to use recursion to achieve clue binary tree" article.
Description: point the empty left child pointer domain of the node in the binary tree to the precursor node and the empty right child pointer domain to the successor node.
Code:
# pragma warning (disable:4996) # include#includetypedef struct TreeNode {char data; struct TreeNode * lchild, * rchild; int ltag, rtag;} Tree,*BTree;BTree Build_Tree (void) {BTree T; char ch; scanf ("% c", & ch); if (ch ='#') {T = NULL;} else {T = (BTree) malloc (sizeof (Tree)); T-> data = ch; T-> ltag = 0; T-> rtag = 0; T-> lchild = Build_Tree () T-> rchild = Build_Tree ();} return T;} / / pre-threaded void Pre_Thread (BTree cur, BTree * pre) {if (cur & & cur- > ltag==0) {printf ("% c", cur- > data); if (cur- > lchild = = NULL) {cur- > lchild = * pre; (* pre)-> ltag= 1; cur- > ltag= 1;} if (cur- > rchild = = NULL) {cur- > rtag = 1 } if (* pre & & (* pre)-> rtag = = 1) {(* pre)-> rchild = cur;} * pre = cur; Pre_Thread (cur- > lchild, pre); Pre_Thread (cur- > rchild, pre);}} / / Central sequence void In_Thread (BTree cur, BTree * pre) {if (cur) {In_Thread (cur- > lchild, pre); printf ("% c", cur- > data); if (cur- > lchild==NULL) {cur- > lchild= * pre Cur- > ltag = 1;} if (cur- > rtag = = NULL) {cur- > rtag = 1;} if (* pre & & (* pre)-> rtag = = 1) {(* pre)-> rchild = cur;} * pre = cur; In_Thread (cur- > rchild, pre);}} / / sequenced void Post_Thread (BTree cur, BTree * pre) {if (cur) {Post_Thread (cur- > lchild, pre); Post_Thread (cur- > rchild, pre) Printf ("% c", cur- > data); if (cur- > lchild = = NULL) {cur- > lchild = * pre; cur- > ltag = 1;} if (cur- > rchild = = NULL) {cur- > rtag = 1;} if (* pre & & (* pre)-> rtag = = 1) {(* pre)-> rchild = cur;} * pre = cur;} int main (void) {BTree Tmeans pendant null; T = Build_Tree (); Pre_Thread (T, & p) / / In_Thread (T, & p); / / Post_Thread (T, & p); return 0;} the above is about "how to use recursion to realize clue binary tree in C language". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.