package Reversedoubleinkedlist;
/**
* @author 真他喵的学不动咯
* @create 2022-08-10--20:02
*/
public class Doublereverse { //实现双链表的逆序
public static class DoubleNode{
//属性
public int value;
public DoubleNode last;
public DoubleNode next;
//构造器
public DoubleNode(int data){
value=data;
}
}
//双链表反转方法
public static DoubleNode reverseDouble(DoubleNode head){
DoubleNode pre=null;
DoubleNode next =null;
while (head!=null){
next=head.next; //为了方便把head跳到next的位置
// 即head=next,毕竟还是要往后把head指针传递
head.next=pre;
head.last=next;
pre=head;
head=next;
}
return pre;
}
}
//实现双链表的逆序
最新推荐文章于 2022-11-15 17:47:45 发布