Java implements stack and queue data structures through LinkedList

Source: Internet
Author: User

1  PackageCom.shb.java;2 3 Importjava.util.LinkedList;4 5  Public classTestlinkedlist {6 7     /**8      * @authorshaobn9 * @Describe: Implementing Queues and stacks with LinkedListTen      * @paramargs One * @Time: 2015-8-27 pm 10:28:33 A      */ -      Public Static voidMain (string[] args) { -         //TODO auto-generated Method Stub thedolinkedlist DLL =Newdolinkedlist (); -String []STR = {"Java", "PHP", "C", "C + +"}; - testadd (DLL, str); -          while(!testemp (DLL)) { + Sysmethod (Testget (DLL)); -         } +System.out.println ("Execution Complete"); A     } at      -      Public Static voidsysmethod (Object obj) { -          - System.out.println (obj); -     } -      Public Static voidTestadd (dolinkedlist dll,string[] str) { in          for(String s:str) { - Dll.addele (s); to         } +     } -      Public StaticString testget (dolinkedlist dll) { the         returnDll.getele ();  *     } $      Public Static Booleantestemp (dolinkedlist dll) {Panax Notoginseng         if(Dll.isemp ()) { -             return true; the}Else { +             return false; A         } the     } + } - classdolinkedlist{ $     PrivateLinkedlist<string>LinkedList; $      Publicdolinkedlist () { -          This. LinkedList =NewLinkedlist<string>(); -     } the      Public voidAddele (String str) { -         Wuyi Linkedlist.add (str); the     } -      PublicString Getele () { Wu         returnLinkedlist.removefirst (); -     } About      Public Booleanisemp () { $         returnlinkedlist.isempty (); -          -     } -}

A simple small program, the package is not very good, written in the middle of the night, if there are errors, you are welcome to point out, thank you.

Java implements stack and queue data structures through LinkedList

Related Article

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.