小编Cai*_*ico的帖子

冒泡手动排序Java中的链接列表

这是我的第一个问题.我试图在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)

java linked-list bubble-sort

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

bubble-sort ×1

java ×1

linked-list ×1