Redian新闻
>
陌陌在WIFI 下很慢
avatar
陌陌在WIFI 下很慢# PDA - 掌中宝
l*c
1
If there is an tree structure data, design an algorithm for function next()
which returns one data each time and this function will access all the data
only once.
大家用什么方法呢?
avatar
c*h
2
在4g时快多了。可是我的WIFI 比4g快,其它app都是WIFI 快。就陌陌异常。这是什么
原理?
avatar
C*U
3
是说tree的node只access一次吧 但是可以把数据存起来吧?
这个好像我身边有个人被微软问到了
用bfs 或者dfs可以吧

)
data

【在 l****c 的大作中提到】
: If there is an tree structure data, design an algorithm for function next()
: which returns one data each time and this function will access all the data
: only once.
: 大家用什么方法呢?

avatar
l*c
4
我也不是很清楚,题就是这样些的。
dfs,不也需要一个visited来记录吗?那就是需要走两遍了。
我的理解是用recursion的in order遍历。要是non-recursion就需要stack了,就有节
点走了2遍;recursion的算不算1遍呢?

【在 C***U 的大作中提到】
: 是说tree的node只access一次吧 但是可以把数据存起来吧?
: 这个好像我身边有个人被微软问到了
: 用bfs 或者dfs可以吧
:
: )
: data

avatar
C*U
5
bfs就不用visit两遍啊 把他们都放到queue里面去

【在 l****c 的大作中提到】
: 我也不是很清楚,题就是这样些的。
: dfs,不也需要一个visited来记录吗?那就是需要走两遍了。
: 我的理解是用recursion的in order遍历。要是non-recursion就需要stack了,就有节
: 点走了2遍;recursion的算不算1遍呢?

avatar
l*c
6
这题,用bfs能解吗?

【在 C***U 的大作中提到】
: bfs就不用visit两遍啊 把他们都放到queue里面去
avatar
s*o
7
用 BFS
static {
Queue queue;
queue.enqueue(root);
}
Node next() {
Node x = queue.dequeue();
if (x != null) {
for (Node c: x.children()) {
queue.enqueue(c);
}
}
return x;
}
avatar
w*x
8
struct NODE
{
int nVal;
NODE* pLft;
NODE* pRgt;

NODE(int n) : nVal(n), pLft(NULL), pRgt(NULL) {}
};
class CIterator
{
public:
CIterator(NODE* pRoot)
{
pushLft(pRoot);
}

NODE* GetNext()
{
if (m_stk.empty()) return NULL;

NODE* pRet = stk.top();
stk.pop();

pushLft(pRet->pRgt);

return pRet
}

private:
void pushLft(NODE* pNode)
{
NODE* pIter = pNode;
while (NULL != pIter)
{
m_stk.push_back(pIter);
pIter = pIter->pLft;
}
}
private:
stack m_stk;
};
avatar
l*c
9
太强了吧~我完全不会这种利用C++ class的方法,怎么学来的啊大牛~

【在 w****x 的大作中提到】
: struct NODE
: {
: int nVal;
: NODE* pLft;
: NODE* pRgt;
:
: NODE(int n) : nVal(n), pLft(NULL), pRgt(NULL) {}
: };
: class CIterator
: {

avatar
r*h
10
这个是binary tree in order traversal的non recursion解法吗?

【在 w****x 的大作中提到】
: struct NODE
: {
: int nVal;
: NODE* pLft;
: NODE* pRgt;
:
: NODE(int n) : nVal(n), pLft(NULL), pRgt(NULL) {}
: };
: class CIterator
: {

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。