单链表的逆置

【单链表的逆置】单链表的逆置。例如:输入字符串abcd,输出字符串dcba

class Lnode{ char data; Lnode next; }public class Main { //返回带头结点的单链表L的逆转链表 public static Lnode Reverse( Lnode L ) { Lnode Old_head, New_head, Temp; New_head = null; Old_head = L.next; while ( Old_head != null ){ Temp = Old_head.next; Old_head.next= New_head; New_head = Old_head; Old_head = Temp; } L.next= New_head; return L }public static void main(String[] args) { String str = null; Lnode La = new Lnode(); La.next = null; Lnode r = La; //尾指针 Lnode Lb = new Lnode(); Scanner scanner = new Scanner(System.in); str = scanner.next(); //尾插法 for(int i=0; i

    推荐阅读