Conversion between sequential storage and linked Storage

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.