Data Structure Java stack stack and queue Queue

sponsored links
My other blog on the image to the

Data Structure Java stack stack and queue Queue

Google found that most of the article are achieved through the LinkedList class, of course, there are built-in Stack class JDK

Recalling the set of JDK provided classes

Container (set) framework as follows:

Collections deposited in the java.util package. Collections are objects stored in a reference, rather than the object itself.

There are three kinds of collection types: set (set), list (list) and map (mapping).

Collection Interface

├ List Interface

│ ├ LinkedList list

│ ├ ArrayList order structure of dynamic array class

│ └ Vector Vector

│ └ Stack stack

Map Interface

├ Hashtable

├ HashMap

└ Set Interface

Collection <- Set <- HashSet

Collection <- Set <- HashSet <- LinkedHashSet

Collection <- Set <- SortedSet (also interfaces) <- TreeSet

LinkedList, access JDK

List interface linked list implementation. To achieve a list of all the optional operations, and allow all the elements (including null)

LinkedList class also the beginning and end of the list get, remove and insert elements to provide a unified naming. These operations allow linked lists for stacks, queues, or double-ended queue

Note that this implementation is not synchronized

JDK itself of the Stack class

Provide the usual push and pop operations, and the selection of the vertex stack peek method to test whether the stack empty empty method to find the items in the stack and determine the distance from the top of the stack, a total of five methods.

JDK itself to achieve this class this class inherits from Vector (since JDK1.0)

Stack data structure definition and basic operations

Stacks and queues are all linear structure, are two in operation subject to certain restrictions on the special linear form, they are simpler than the general linear form.

Stack (stack) is to limit the linear elements in the table insert and delete only the linear form of the same side for a special linear form. One end to allow insertion and deletion, known as the top of the stack (top), the other end is fixed at one end, called the bottom of the stack

Top of the stack, the stack bottom, empty stack, stack characteristics,

Return stack into the stack

Stack operations:

Initialize the stack, into the stack push, a stack pop,, take the stack elements (that is, see the next to a stack of elements, also called peek), check air

LinkedList stack used to achieve

Actually, the key is to achieve into the stack push, a stack pop,, elements of which are several ways to take the stack

package org.simoncook.examtest;

import java.util.LinkedList;

public class MyStack (

private LinkedList ll = new LinkedList ();

public void push (Object obj) (

/ / Insert the specified element at the beginning of this list.

ll.addFirst (obj);


public Object pop () (

/ / Removes and returns the first element of this list.

return ll.removeFirst ();


public Object peek () (

/ / Returns the first element of this list.

return ll.getFirst ();


public boolean empty () (

return ll.isEmpty ();



Queue data structure


Queue (Queue) definition

Examples of the characteristics of the queue queue queue basic operations (1) into the team operation: InQueue (q, x)
(2) a team operation: OutQueue (q, x)
(3) reading the first element of team: ReadFront (q, x)
(4) shows the queue element ShowQueue (q)
(5) sub-team air operations: QEmpty (q)
(6) sub-team full operation: QFull (q)
(7) Find the queue length Qlen (q)

Implementation code:
package com.gc.list;
import java.util .*;
public class MyQueue (

private LinkedList ll = new LinkedList ();
/ / Enqueue operation
public void put (Object o) (
ll.addLast (o);
/ / Use removeFirst () method returns the first data queue, and then remove it from the queue
/ / A team operation
public Object get () (
return ll.removeFirst ();

public boolean empty () (
return ll.isEmpty ();
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Data Structure Java stack stack and queue Queue

  • rails to add full-featured auto-fill

    Automatic text box is a complete help users quickly and accurately fill out the form function, which is based on the database already exists in certain fields of data. We have Google Suggest ( as an example of such a fea

  • ajax input prompt implementation

    Projects have used at the time entered by the user to give some tips, suggesting that the contents are extracted from the database (in Chinese). So a google search under the amended part of their code to share with you. Attachment is available at the ...

  • Mapping tool for browser-side analysis

    Divided into two main categories: One category is pure Javascript Advantages: does not require any plug-in, no understanding of Flash Recommend Product: 1 Flot Function well, the document is too easy 2 EJS commercial pu ...

  • Manual configuration in UBUNTU under ruby on rails environment

    Careless mistake for the day before yesterday, the sources, the results after 810 error after the upgrade, the loss of response button. On google found a lot of trouble really, lucky point modification under the / etc/X11/xorg.conf to restore both, b ...

  • Ruby Rails system calls the use of Ping

    Want to use call system commands under RoR, the general exec and system and the syscall Want to use in Rails, the call ping command The most common are ruby support Ping usage is as follows: Ping contains routines to test for the reachability of remote ho

  • Rails source code analysis (4): Request / Response

    1) Rails defines two abstract class: AbstractRequest and AbstractResponse code is not posted, first take a look at Response. 2) is mainly responsible for the specific ctgi_process.rb main interface is responsible for implementation methods of impleme ...

  • WEB test summary (architecture, design) the best part

    1, for a total test architecture 1) thin-client, business logic rules in the server-side implementation of the majority. Such as news sites, portals, information websites. 2) fat client, a high security requirements, frequent interaction, complex bus ...

  • Use Ext JS to read the JsonReader complex object json

    Today was how to resolve the following complex json object to the difficult living over a long time .. did not find documentation how to read JsonReader Ways json object (possibly also because of their limited level of E the text did not correctly underst

  • NoClassDefFoundError: javax / servlet / Servlet

    In the project in order to achieve a listener in web.xml set up a listener, did start in Tomcat actually occurred after java.lang.NoClassDefFoundError: javax / servlet / ServletContextListener this anomaly google and found the reasons for the lack of serv

  • The level Hibernate cache

    Hibernate cache level: (1) a cache is very short and the session life cycle consistent, also known as session-level cache-level cache or transaction-level cache (2) Ways of Supporting level cache: get (); load (); iterator (); only entity object cach ...

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries