The following section of code accurately describes the Java implementation of a single list of reverse order, the specific content is not done in detail, there is a need for friends can directly copy the
Package Com.ckw.mianshi;
/**
* Java implementation of a single list of the reverse order
* @author Administrator */Public
class Singlelinkedreverse {
class Node {
int data;
Node Next;
public Node (int data) {
this.data = data;
}
}
public static void Main (string[] args) {
singlelinkedreverse SLR = new Singlelinkedreverse ();
Node head, tail;
Head = Tail = Slr.new Node (0);
for (int i=1; i<10; i++) {
node P = slr.new node (i);
Tail.next = p;
tail = p;
}
tail = head;
while (tail!= null) {
System.out.print (tail.data+);
tail = Tail.next;
}
Head = reverse (head);
System.out.println ();
while (head!= null) {
System.out.print (head.data+);
head = Head.next;
}
}
private static node reverse (node head) {
node p1,p2 = null;
P1 = head;
while (Head.next!= null) {
P2 = head.next;
Head.next = P2.next;
P2.next = p1;
P1 = p2;
}
return P2
}
}
Test results:
0 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 0
The above is the Java implementation of a single linked list of reverse code, I hope we can like.