现在的位置: 首页 > 综合 > 正文

Ch4.4: array to Balanced tree and print each level

2014年07月07日 ⁄ 综合 ⁄ 共 476字 ⁄ 字号 评论关闭

Q: an ordered array is given, need to convert into a balanced binary tree and then BFSly print each level as a D-dimentional linked list

Need to understand list, vector, BFS, recursion, scope of member function, call-by-reference, class, template.

The main method is the linked list form processing.

1: push the given head into the list, then push it into a vector.

2. if the vector is not empty, push all the left/right children of the head into a temporary list, after BFS this level, push the temp list into the previous vector as output.

Here is the source code and output.

抱歉!评论已关闭.