Algs4-1.3.26编写一个remove()方法

1.3.26编写一个方法remove(),接受一条链表和一个字符串key作为参数,删除链表中所有item域为key的结点。
答:
public  insertAfter(Node first,String key)
{
  Node  x=new Node();
  x.next=first;
  if(x.next!=null && x.next.item==key)
     x.next=x.next.next;
  first=x.next;
 //  
  while(x.next!=null)
  {
      if(x.next.item==key)
         x.next=x.next.next;
      else
         x=x.next;
  }
  //
  last=x;
 }

猜你喜欢

转载自www.cnblogs.com/longjin2018/p/9849581.html