If my input sequence is: 2 13 14 5 6 17 8 9 2 3 I created two-forked trees such as: 2 13 14 5 6 17 8 9 2 Database Structure with a binary table Create #include
#include
Using namespace std; structure; bintree * left, * right;}; void del (bintree * p) {if (p-> left) Del (p-> left); if (p-> right) DEL (P-> Right); DELETE P;} bintree * Creat (int * node, int & point, 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 <
Data << "; DFS (P-> Left); DFS (P-> Right);} int main (int Argc, 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;}