Java implements single-linked list inversion

Source: Internet
Author: User

1 classLnode2 {3      PublicLnode Next;4      Public intdata;5 }6 /*Reverse Linked list*/7 classNizhi8 {9     Private StaticLnode head =NewLnode ();Ten     Private Staticlnode node; One     Private StaticLnode tail; A     Private Static intindex; -     Private StaticLnode Newhead =NewLnode (); -      Public Static voidMain (string[] args) { the         int[] Nums = {1,2,3,4,5,6,7,8,9,10};  -Head.data = Nums[0]; -Tail =head; - Createline (nums); +System.out.println ("—————————————————— linked list order printing ———————————————————"); - PrintLine (head); + Nizhi (); ASystem.out.println ("—————————————————— linked list reverse print ———————————————————"); at PrintLine (newhead); -     } -  -     Private Static voidCreateline (int[] nums) { -          while(index<10) -         { innode =NewLnode (); -Tail.next =node; toNode.data =Nums[index]; +Node.next =NULL; -Tail =node; theIndex + +; *              $         }Panax Notoginseng     } -  the     Private Static voidPrintLine (Lnode head) { +node =head; A          while(node!=NULL&&node.next!=NULL){ thenode =Node.next; + System.out.println (node.data); -         } $     } $  -     Private Static voidNizhi () { -          thenode =Head.next; -         //traverse the original linked list node and head interpolation to the new head node .Wuyi          while(node!=NULL) the         { -Lnode temp =NewLnode (); WuTemp.data =Node.data; -             //node.next = Node.next.next; AboutTemp.next =Newhead.next; $Newhead.next =temp; -              -System.out.println ("Temp.data=" +temp.data); -node =Node.next; A         } +     } the}

Java implements single-linked list inversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.