import java.util.*;

class A //结点

{

       intx;

       Anext;

}

 

class B //链表

{

       Ahead;

       voidcreate()

       {

              Aa1,a2,a3;

              a2=newA();

              Scanners=new Scanner(System.in);

              System.out.println("请输入数值");

              a2.x=s.nextInt();

              a1=a2;

              a3=a2;

             

              while(a2.x!=0)

              {

                     a2=newA();

                     System.out.println("请输入数值");

                     a2.x=s.nextInt();

                    

                     a3.next=a2;

                     a3=a2;

              }

              a2.next=null;

              head=a1;

       }

      

       voiddisp()

       {

              Aa=head;

              while(a.next!=null)

              {

                     System.out.print(a.x+"\t");

                     a=a.next;

              }

              System.out.println();

       }

      

       voiddelete(int key)

       {

              //第一种情况,删除的结点就是第一个

              Aa=head;

              if(head.x==key)

              {

                     head=head.next;

                     a=null;

                     return;

              }

             

              //第二种情况,删除的结点是最后一个

              Aa2=new A();

              while(a.next.next!=null)

              {

                     a2=a;

                     a=a.next;//循环一直跑到链表的最后一个

                    

                     System.out.println("xxxxxx:   "+a.x);

                     System.out.println("yyyyyy:   "+a2.x);

              }

             

      

             

             

              if(a.x==key)

              {

                     a=null;

                     return;

                    

              }

              /*

              if(a.x==key)

              {

                     if(a2.next.next==null)

                            System.out.println("Helloworld");

                     a2.next.next=null;

                     return;

              }

              */

             

             

              a=head;

              //第三种情况,在中间          

 

              while(a.next!=null)

              {

                     Aa3=new A();

                     a3=a;

                     a=a.next;

                     if(a.x==key)

                     {

                            a3.next=a.next;     

                     }    

              }

 

       }

}

 

public class Demo1

{

       publicstatic void main(String argc[])

       {

              Bb1=new B();

              b1.create();

              b1.disp();

              b1.delete(11);

              b1.disp();

       }

}