为什么我的链表不打印?它甚至创建列表?

时间:2016-03-30 23:28:11

标签: java methods system.out

我是编程新手,这是我在stackoverflow上的第一篇文章。下面是代码我正在尝试使用for循环创建链接列表,然后只是打印出列表。我还使用链表的基本基本方法(不使用内置函数)来完成此操作。我不确定为什么不打印。我已经观看了几个视频,在stackoverflow上搜索,并搜索了该主题,但无济于事。

package basiclinkedlist;
import java.util.*;

public class BasicLinkedList {

    public class node{
        public int data;
        public node next;
    }


    public node front;
    public void init(){
        front = null;
    }

    public node makeNode(int num){
        node newNode;
        newNode = new node();
        newNode.data = num;
        newNode.next = null;
        return newNode;
    }

    public node findTail(node front){
        node current;
        current = front;
        while(current.next != null){
            current = current.next;
        }
        return current;
    }

    public void makeList(int length){
        int j;
        node tail;
        front = makeNode(0);
        tail = front;
        for(j=1;j<length;j++){
            tail.next = makeNode(j);
            tail = tail.next;
        }

    }

    public void showList(){
        node current;
        current = front;
        while(current != null){
            System.out.println(current.data);
            current = current.next;
        }
    }


    public static void main(String[] args){
        BasicLinkedList obj = new BasicLinkedList();
        BasicLinkedList obj1 = new BasicLinkedList();
        BasicLinkedList obj2 = new BasicLinkedList();
        obj.init();
        obj1.makeList(9);
        obj2.showList();

    }


}

0 个答案:

没有答案