package com.kpp; /** * 单链表逆置 * 将单链表从第一个结点和第二个节点之间断开,然后将第2,3。。。个结点依次插入第一个结点之前 * @author kpp * */ class LNode{ private String data; private LNode next; } public class LinkedListReverse { private static void reverse(LNode head){ if(head == null||head.next == null||head.next.next==null) return; LNode p = head.next,next; head.next.next=null; while(p != null){ LNode q = p.next; p.next = head.next; head.next = p; p = q; } } }
时间: 2024-11-01 11:15:53