小编pij*_*olu的帖子

如何检查特定IP地址是否连接到网络

我想创建一个应用程序来查找网络上的特定 IP 地址是否在线。我已经知道IP了。我对 C# 很陌生,但想知道是否有人可以给我一个简单的解决方案。谢谢。

.net c# network-programming wifi

3
推荐指数
1
解决办法
5847
查看次数

二进制搜索树IEnumerator.MoveNext()在递遍实现时非递归.如何?

在构建了一个BST<Tkey,TValue>BSTNode<Tkey,TValue>节点组成的二叉搜索树之后,我试图为它实现IEnumerable接口.

这就是我构建的方式BSTNodeEnumrator<Tkey,TValue>:

public class BSTNodeEnumerator<TKey, TValue> : IEnumerator<BSTNode<TKey, TValue>> where TKey : IComparable<TKey>
{
    private Stack<BSTNode<TKey, TValue>> _stack;

    public BSTNodeEnumerator(BSTNode<TKey, TValue> root)
    {
        _stack = new Stack<BSTNode<TKey, TValue>>();
        _current = null;
        _root = root;
    }

    // ... rest of the implementation
}
Run Code Online (Sandbox Code Playgroud)

我传入root节点并且_current是枚举的结果.我也试图使用堆栈,因为我不像AVL BST那样跟踪父节点.

现在我希望枚举器以非递归的方式按顺序遍历树.这应该导致排序的枚举,因为bst的属性,这是伟大的,因为这正是我想要实现的.

用于在伪代码中遍历的非递归算法,如本维基百科文章中所述

    iterativeInorder(node)
  s ? empty stack
  while (not s.isEmpty() or node ? null)
    if (node ? null)
      s.push(node)
      node ? node.left
    else
      node ? …
Run Code Online (Sandbox Code Playgroud)

c# algorithm ienumerable enumerator binary-search-tree

3
推荐指数
1
解决办法
689
查看次数