//在双链表删除倒数第k个节点
public class DoubleNode{
public int value;
public DoubleNode last;
public DoubleNode next
public DoubleNode(int data){
this.data.data;
}
}
public DoubleNode removeLastKthNode(DoubleNode head,int lastKth){
if(head==null||lastKth<1){
return head;
}
DoubleNode cur=head;
while(cur!=null){
lastKth--;
cur=cur.next;
}
if(lastKth==0){
head=head.next;
head.last=null;
}
if(lastKth<0){
cur=head;
while(++lastKth!=0){
cur=.cur.next;
}
DoubleNode newNext=cur.next.next;
cur.next=newNext;
if(newNext!=null){
newNext.last=cur;
}
}
return head;
}
链表-在双链表中删除倒数第k个节点
猜你喜欢
转载自blog.csdn.net/weixin_42146769/article/details/88381677
今日推荐
周排行