这是我的第一个问题.我试图在java中手动排序整数的链接列表,我无法弄清楚我的代码有什么问题.有什么建议?我没有得到任何错误,但我的输出仍然无序.我尝试了几种不同的方式,但没有任何效果.如果有人能帮助我,我感激不尽.
public class Node {
int data;
Node nextNode;
public Node(int data) {
this.data = data;
this.nextNode = null;
}
public int getData() {
return this.data;
}
} // Node class
public class DataLinkedList implements DataInterface {
private Node head;
private int size;
public DataLinkedList(){
this.head = null;
this.size = 0;
}
public void add(int data) {
Node node = new Node(data);
if (head == null) {
head = node;
} else {
Node currentNode = head;
while(currentNode.nextNode != null) …Run Code Online (Sandbox Code Playgroud)