gpt4 book ai didi

java - 一个链表打印,但另一个非空链表不打印 : Revised and expanded

转载 作者:行者123 更新时间:2023-12-01 12:06:28 26 4
gpt4 key购买 nike

我修改了这个问题。我有两个链表,一个用于每种对象类型(顶点、边)。打印边的链表,但不打印顶点的链表。如果我切换顺序或将代码分成两个方法,这个问题仍然存在。

这是打印方法

public void printList() {        
ListIterator edgeIter = m_EdgeList.listIterator();
Edge e;
while (edgeIter.hasNext()) {
e = (Edge)edgeIter.next();
System.out.println(e.getName()+e.getOrientation());
}
ListIterator vertexIter = m_VertexList.listIterator();
Vertex v;
while (vertexIter.hasNext()) {
v = (Vertex)vertexIter.next();
System.out.println(v.getName()+":"+v.getIncidentEdge(1).getName()+ v.getIncidentEdge(1).getOrientation()+v.getIncidentEdge(2).getName()+ v.getIncidentEdge(2).getOrientation());
}
}

链表不为空。当我创建它时,我打印了尺寸并看到它增加了。另外,当我打印原始列表,然后打印我得到的尺寸的序言时:

[com.expertdecision.topology.classification.struct.Vertex@de6ced、com.expertdecision.topology.classification.struct.Vertex@c17164、com.expertdecision.topology.classification.struct.Vertex@1fb8ee3]曲面:f1:由 3 个顶点组成

看起来顶点迭代器没有按预期工作,但我使用它的方式与使用边迭代器的方式相同。

下面是从边数组中为边创建链接列表的方法:

 public void setEdgeList(Edge[] edges) {
String method = "setEdges(Edge[])";
if (m_Tracing) Tracing.print(m_Class + "::" + method);
m_EdgeList = new LinkedList<Edge>();
ListIterator iter = m_EdgeList.listIterator();
for (int i=0; i<m_EdgeCount; i++) {
iter.add(edges[i]);
}
}

这是为顶点创建链表的方法:

 /**
* Create vertices for every pair of edges
*/
public void createVertices() {
String method = "createVertices()";
if (m_Tracing) Tracing.print(m_Class + "::" + method);
int iVertex;
String[] vlabel = {"A","B","C","D","E","F","G"};
//This implementation uses a LinkedList
m_VertexList = new LinkedList<Surface>();
ListIterator eIter = m_EdgeList.listIterator();
Vertex v;
Edge e1;
Edge e2;
//
iVertex = 0;
e1 = (Edge)eIter.next();
while (eIter.hasNext()) {
e2 = (Edge)eIter.next();
v = new Vertex(vlabel[iVertex],e1, e2);
if (m_Debugging) System.out.println("Adding " + v.getName()+ " to vertex list");
m_VertexList.add(v);
if (m_Debugging) System.out.println("Current size of vertex list is " +m_VertexList.size());
iVertex++;
e1 = e2;
}
//Vertex for the last-first edge
e2 = (Edge)m_EdgeList.get(0);
v = new Vertex(vlabel[iVertex],e1, e2);
if (m_Debugging) System.out.println("Adding " + v.getName()+ " to vertex list");
m_VertexList.add(v);
if (m_Debugging) System.out.println("Current size of vertex list is " +m_VertexList.size());
if (m_Debugging) printList();
}

最佳答案

要么使用调试器(比如在 Eclipse 中),要么设置一些 System.out 行来验证,但似乎 arraylist 是空的并且没有进入 while 循环。

关于java - 一个链表打印,但另一个非空链表不打印 : Revised and expanded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27552373/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com