Sequential storage is converted to linked storage:
Btreenode * Create (char * STR, int pose, int size) // subscript starts from 0 {char ch; btreenode * t; char * P = STR; ch = P [pose]; If (CH = '#' | pose> = size) return NULL; // It indicates an empty node else {T = (btreenode *) malloc (sizeof (btreenode); // create a new node T-> DATA = CH if it is not empty; // The data field of the new node is the read character T-> lchild = create (p, 2 * pose + 1, size); // create the left subtree T-> rchild = create (p, 2 * pose + 2, size ); // create the right subtree} return (t );}
Link storage is converted to sequential storage:
Char A [200]; // ordered storage array int flag; // determines whether it is an empty tree binode * creat (binode * BT, int K) {char ch; CIN> CH; if (CH = '#') {bt = NULL;} else {flag = 1; bt = new binode; Bt-> DATA = CH; A [k] = CH; BT-> lchild = creat (BT-> lchild, (k) * 2); Bt-> rchild = creat (BT-> rchild, (k) * 2 + 1);} return Bt ;}
Initialize to creat (root, 1 );