/ Published in: C++
string型データ structure は最終的に 2n + 1 bit になるにすぎない。ここで n は内部ノードの数である。structure型データの長さすら記録する必要がない。次の関数を実行すれば、情報が全く失われていないことがわかるだろう。これはstring型データから二分木を再構築する: inside of string node will be 2n + 1 bit therefore, you don't have to calculate a length of string data. the benefit of using following code is that you don't loose any data.
Expand |
Embed | Plain Text
function EncodeSuccinct(node n, bitstring structure, array data) { if (n = nil)// then // structure ã�®æ��å¾�ã�« 0 ã��追å� ã��ã�� // add 0 at end of structure else // structure ã�®æ��å¾�ã�« 1 ã��追å� ã��ã�� -> add 1 at end of structure // data ã�®æ��å¾�ã�« n.data ã��追å� ã��ã�� -> addn.data at end of data EncodeSuccinct(n.left, structure, data) EncodeSuccinct(n.right, structure, data) } // string type // remake a tree from string type data structure function DecodeSuccinct(bitstring structure, array data) { // structure ã�®æ��å��ã�®ã��ã��ã��ã��å��ã��é�¤ã��ã��ã��ã�®ã��ã��ã��ã�� b ã�«å�¥ã��ã�� // remove the first bit and then put the first bit at b if ( b = 1 ) then // æ�°ã��ã��ã��ã�¼ã�� n ã��ä½�ã�� // make n from new node // dataã�®æ��å��ã�®è¦�ç´ ã��å��ã��é�¤ã��ã��ã��ã�®è¦�ç´ ã�� n.data ã�«å�¥ã��ã�� // remove first element of data and put it in n.data n.left = DecodeSuccinct(structure, data) n.right = DecodeSuccinct(structure, data) // n ã��è¿�ã�� else // nil ã��è¿�ã�� // return nil; }
You need to login to post a comment.
