V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
TigerS
V2EX  ›  问与答

谁懂如何把Java的代码Transfer成Python的呢? 期中涉及到两个Java的Class 换成一个Python的. 只需要两个Function

  •  
  •   TigerS · 2013-04-13 09:56:15 +08:00 · 2358 次点击
    这是一个创建于 4201 天前的主题,其中的信息可能已经有所发展或是发生改变。
    public int distance (Vertex x, Vertex y) {
    int returnVal = 0;
    Queue que = new LinkedList();
    x.touched = true;
    que.add(x);
    while (!que.isEmpty()) {
    returnVal++;
    Vertex n = (Vertex)que.remove();
    Vertex child = null;
    while ((child = getUnvisited(n))!=null) {
    if (child.value==y.value)
    return returnVal;
    child.touched=true;
    que.add(child);
    }
    }
    return returnVal;
    }

    public int diameter () {
    int maxDistance = 0;
    int tempDistance = 0;
    Vertex one;
    Vertex two;
    for (int x = 1; x < numNodes; x++) {
    one = (Vertex)vert.get(x);
    for (int y = 0; y < x; y++) {
    two = (Vertex)vert.get(y);
    tempDistance = distance(one, two);
    if (tempDistance > maxDistance)
    maxDistance = tempDistance;
    refreshTouched();
    }
    }
    return maxDistance;
    }

    ==============

    Vertex class

    public class Vertex {
    public boolean touched;
    public int value;
    public Vertex (int value) {
    touched = false;
    this.value = value;
    }
    }

    ====================

    主要需要实现上面的两个功能.
    有些部分比如 x.touched = true; 这个需要调用到第二个class vertex 不知道怎么在Python中(一个文件,没有class)表示
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2563 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 76ms · UTC 09:13 · PVG 17:13 · LAX 02:13 · JFK 05:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.