//结点
public class Node {
public int value;
public Node next;
public Node(int value){
this.value = value;
}
}
//实现类
public class LinkListNiShuPrint {
//创建数据
public Node createDatas(){
Node headNode = new Node(0);
Node tempHead = null;//暂时的头
tempHead = headNode;
for (int i = 1; i<10; i++) {
Node newNode = new Node(i);
tempHead.next = newNode;
tempHead = newNode;//设为新的头
}
return headNode;
}
//逆序输出
public Node datasNiXuPrint(Node headNode){
Node pNode = null;
Node hNode = null;//指向当前列表的第一个Node
hNode = headNode;
while (headNode.next != null) {
pNode = headNode.next;
headNode.next = pNode.next;
pNode.next = hNode;
hNode = pNode;
}
return hNode;
}
}
//展示
public static void main(String[] args) {
LinkListNiShuPrint linkListNiShuPrint = new LinkListNiShuPrint();
Node headNode = linkListNiShuPrint.datasNiXuPrint(linkListNiShuPrint.createDatas());
while (headNode != null) {
Node tempNode = headNode.next;
System.out.println("链表结点值: "+headNode.value);
headNode = tempNode;
}
}