March 2019
Intermediate to advanced
336 pages
9h 9m
English
In the following code snippet, the main method creates an AVL tree by inserting nodes with the 5, 3, 8, 7, 6, and 10 keys. Nodes with the 3 and 7 keys are removed. The tree data structure is converted in to JSON in bytes. The JSON bytes are printed after being changed to a string:
//main methodfunc main() { var treeNode *TreeNode fmt.Println("Tree is empty") var avlTree []byte avlTree, _ = json.MarshalIndent(treeNode, "", " ") fmt.Println(string(avlTree)) fmt.Println("\n Add Tree") InsertNode(&treeNode, integerKey(5)) InsertNode(&treeNode, integerKey(3)) InsertNode(&treeNode, integerKey(8)) InsertNode(&treeNode, integerKey(7)) InsertNode(&treeNode, integerKey(6)) InsertNode(&treeNode, integerKey(10)) avlTree, _ = json.MarshalIndent(treeNode, ...Read now
Unlock full access