问一个建立二叉查找树(binary search tree)迭代器的有关问题
问一个建立二叉查找树(binary search tree)迭代器的问题
今天看数据结构看到binary search tree,后面有个题目感觉没看明白,题目是这样的
Write an implementation of the set class, with associated iterators using a binary search tree. Add to each node a link to the next smallest and next largest node. To make your code simpler, add a header and tail node which are not part of the binary search tree, but help make the linked list part of the code simpler.
指向下一个最小结点和最大结点的指针,我的理解是如果按照中序遍历的话每个节点指向下一个最小节点的指针就是他的直接前驱而至向下一个最大节点的指针则是他的直接后继。比如插入序列4,2,9,那么2的下一个最小节点指针就是null,最大节点指针就是4,以此类推。不知道这个理解对不对
如果是对的话,那么这个是有助于简化迭代器的代码了
希望大家多给点意见,谢谢~~
------解决方案--------------------
说还要加指向最大最小的指针
今天看数据结构看到binary search tree,后面有个题目感觉没看明白,题目是这样的
Write an implementation of the set class, with associated iterators using a binary search tree. Add to each node a link to the next smallest and next largest node. To make your code simpler, add a header and tail node which are not part of the binary search tree, but help make the linked list part of the code simpler.
指向下一个最小结点和最大结点的指针,我的理解是如果按照中序遍历的话每个节点指向下一个最小节点的指针就是他的直接前驱而至向下一个最大节点的指针则是他的直接后继。比如插入序列4,2,9,那么2的下一个最小节点指针就是null,最大节点指针就是4,以此类推。不知道这个理解对不对
如果是对的话,那么这个是有助于简化迭代器的代码了
希望大家多给点意见,谢谢~~
------解决方案--------------------
说还要加指向最大最小的指针