Pro5 Print list from beginning to end (Java)

Source: Internet
Author: User

Note: (1) This shows the difference between Java data structure and C language.

(2) Stack operation is carried out directly using stack.

1  PackageCom.xsf.SordForOffer;2 3 ImportJava.util.Stack;4 5 6 /*7 * Sword means offer8 *pro5 linked list reverse output9  * */Ten  One classlistnode{ A     //Defining Nodes -     intdata; - ListNode Next; the } -  - //reverse printing with stacks - classprintlistreverse{ +     //Enter a head node and then use the stack operation to complete the reverse output. -      Public voidPrint_reverse (ListNode listnode) { +stack<listnode> stack =NewStack<listnode>(); A         //to put a node into the stack at          while(listnode!=NULL){ - Stack.push (listnode); -ListNode =Listnode.next; -         } -         //node out Stack -          while(!Stack.empty ()) { in System.out.println (Stack.pop (). data); -         } to     } +  - } the  Public classPro5linklistreverse { *      Public Static voidMain (string[] args) { $ListNode Node1 =NewListNode ();Panax NotoginsengListNode Node2 =NewListNode (); -ListNode Node3 =NewListNode (); theNode1.data = 1; +Node2.data = 3; ANode3.data = 5; theNode1.next =Node2; +Node2.next =Node3; -Printlistreverse test =Newprintlistreverse (); $ Test.print_reverse (node1); $     } -}

Pro5 Print list from beginning to end (Java)

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.