Two-fork tree hierarchy.

xiaoxiao2021-03-05  28

#include #include

Using namespace std;

Struct bintree {int Data; bintree * left, * right;};

Void del (bintree * p) Del (p-> left); if (p-> right) Del (P-> Right); delete p;} bintree * Creat (int * node, INT & SIZE, INT POS) {IF (POS> = Size) Return Null; bintree * t = new bintree; t-> data = node [POS]; t-> left = Creat (Node, Size, POS * 2 1 ); T-> Right = Creat (Node, Size, POS * 2 2); Return T;}

Void DFS (bintree * p) {if (! p) return; cout << p-> data << "; DFS (P-> Left); DFS (P-> Right);} int main (int Arg, Char * argv []) {bintree * tree; int node [] = {/ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, / 13, 45, 15, 16 , 17, 18, 19, 20, 21, / 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}; int size = sizeof (node) / sizeof (Node [0]); Tree = Creat (Node, Size, 0); DFS (Tree); Del (Tree); System ("Pause"); return 0;} =================== =============================================================================================================================================================================================================

Head: http://community.9cbs.net/expert/topic/3948/3948858.xml? Temp = .7505304

转载请注明原文地址:https://www.9cbs.com/read-34348.html

New Post(0)