Java LinkedList Proprietary method Pee && simulates a stack or queue data structure using LinkedList.

Source: Internet
Author: User

Package Collection;import Java.util.linkedlist;/*linkedlist: Unique method AddFirst ()/addlast (); GetFirst ()/getlast (); Removefirst ()/removelast (); If the list is empty, throw no exception to this element/nosuchelementexception but the JDK1.6 version has an alternative method: Offerfirst ()/offerlast () ;p Eekfirst ()/peeklast () Pollfirst ()/polllast (): Returns the Null*/public class Linklistdemo{public static void main If the list is empty ( String[] args) {linkedlist<string> link = new linkedlist<string> () Link.addfirst ("Java01"); Link.addfirst ("Java02"); Link.addfirst ("Java03"); Link.addfirst ("Java04"); SOP (link); [Java04, Java03, Java02, Java01]/*get method takes only the element remove method to complete the element, but also deletes *//*sop (Link.getfirst ()); SOP (Link.getlast ()); SOP ( Link.removefirst ()), SOP (Link.removelast ()), SOP ("Size:" +link.size ()), */while (!link.isempty ()) {SOP ( Link.removefirst ());}} public static void Sop (Object obj) {System.err.println (obj);}} /////////////////////////////////////////////////////////////////////////////////////////////////////////////// /package collection;import java.util.linkedlist;/* using LinkedList to simulate a stack or queue data structure。 Stack: Advanced out queue: FIFO */class duilie{private linkedlist link;duilie () {link = new LinkedList ();} public void Myadd (Object obj) {link.addfirst (obj);} Public Object MyGet () {return link.removelast ();} public Boolean isNull () {return link.isempty ();}} public class Linklisttest{public static void Main (string[] args) {Duilie dl = new Duilie ();d l.myadd ("Java01");d L.myadd (" Java02 ");d l.myadd (" Java03 ");d l.myadd (" Java04 ");//System.out.println (Dl.myget ());   System.out.println ("============"), while (!dl.isnull ()) {System.out.println (Dl.myget ());}}}

  

Java LinkedList Proprietary method Pee && simulates a stack or queue data structure using LinkedList.

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.