Data Structure Java stack stack and queue Queue

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 ();

分类:Java 时间:2010-04-29 人气:363
blog comments powered by Disqus


  • Basic data structures - stacks and queues 2010-09-20

    The so-called stack, is a basic operation with at least two abstract data types: insert a new element; remove the time element inserted recently.  follow the FILO (First in, last out, LIFO) principle. The so-called queue, is also a basic operation w

  • Data structures (stacks and queues) 2010-11-03

    Commodity shelf management 1, with the realization of stacks and queues # Include <stdafx.h> # Include <stdio.h> # Include <string.h> # Define MaxSize 3 / / Definition of commodity information typedef struct { char name [20]; / / product

  • 3. Stacks and queues 2011-01-06

    First, the stack structure and application of the second, the construction and application of line-up Stack package ch03; public class MyStack { // The underlying implementation is an array private long[] arr; private int top; /** * The

  • perl's pop operations with an array of far right push, shift with the left-most array unshift operation 2010-08-13

    perl's pop operations with an array of far right push, shift operation with unshift array records the left to learn about 1. #!/usr/bin/perl -w 2. use strict; 3. print '@a @b @c @d Values are as 1 2 3',"\n"; 4. my @a = (1..3); 5. pop(@a); 6. pri

  • Convert C + + using SWIG interface to the Java Interface 2010-03-26

    SWIG (Simplified Wrapper and Interface Generator) is the C / C + + Interface into other languages interface tool, which can speak C / C + + library into the other language system. SWIG now have support for Python, Java, C #, Ruby, PHP, R language 10

  • Some commonly used data source Java solutions 2010-10-25

    Java in the data source is javax.sql.DataSource. DataSource can be created with different implementations. Way to create JNDI DataSource Way to create a data source JNDI must first configure the data source connection information related to, that is,

  • Java and SAP's three kinds of data communication 2010-03-22

    JAVA and SAP data interact Summary RFC ways: Java programs to directly access SAP through RFC object (or function may be a popular name right) SAP provides the BAPI (Business Application Programming Interface), BAPI, SAP system to provide a range of

  • json data and data conversion JAVA 2010-07-13

    Transfer from: 1, DTO: Data Transfer Object, Data Transfer Object 2, the date format problem, has also been dealing with 3, json-lib-2.2.2-jdk13.jar (2.1 in the date array of json-> java problem) Tools JsonUtil co

  • The difference between common data structures Java 2010-08-26

    Object Array can store and basic data types, but must be specified when creating the array size is not longer to change, / / Array to store any type of data Vertor is put in the Object. Vertor one-dimensional, Hashmap / Hashtabe two-dimensional; Vert

  • java.lang.LinkageError: loader constraint violation: when resolving interface ... 2010-10-06

    java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory;" the class loader (instance of org/apache/jasper/servlet/JasperLoade

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 黔ICP备15002463号-1

processed in 0.374 (s). 13 q(s)