- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的 printList() 方法的代码:
public String printList() {
String list = "";
Node tempnode = headNode;
while (tempnode != null) {
list = list + tempnode.data + ", ";
tempnode = tempnode.next;
}
return list;
}
我正在使用 System.out.println(myList.printList()); 调用该方法在我的主要。当我调用该方法时,列表本身是正确的,但列表被打印了无数次,我不明白为什么。如有任何帮助,我们将不胜感激!
最佳答案
如果您的列表是循环的(如 @josejuan 提到的),那么这应该可以解决问题。
public String printList()
{
String list = "";
Node tempnode = headNode;
while (tempnode != null)
{
list = list + tempnode.data + ", ";
tempnode = tempnode.next;
if ( tempnode == headNode )
{
break;
}
}
return list;
}
关于java - 为什么我的链表赋值的 printList() 方法会出现无限循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59481805/
我正在为我的类(class)开发一个 List 程序,到目前为止它似乎工作正常,唯一表现奇怪的是 PrintList 函数。假设我编译程序并在第一个节点中压入一个数字(例如 4),然后打印列表,输出为
这是我的 printList() 方法的代码: public String printList() { String list = ""; Node tempnode = headNode; whil
我已经盯着这段代码看了很长一段时间了,我真的想不通如何以及如何进行它的 JUnit 测试。 static void printList(OrderedIntList list) { Syste
#include using namespace std; struct Node { char item; Node *next; }; void inputChar ( Node
这个问题已经有答案了: Difference between -> and . in a struct? (7 个回答) Arrow Operator vs. Dot Operator [closed
如何通过构造一个新方法 printList 来打印这个新的数据结构,该方法显示 LinkedList aList 的内容。 使用(打印)作为模板。 public void actionPerforme
我是一名优秀的程序员,十分优秀!