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