java data structure stack

2011-04-28  来源:本站原创  分类:Java  人气:70 

Create node classes (Node.java)

package com.yz.mystack;

public class Node {
Object data;
Node next;
public Node (Object data) {
this.data = data;
next = null;
}
public Object getData () {
return data;
}
public void setData (Object data) {
this.data = data;
}
public Node getNext () {
return next;
}
public void setNext (Node next) {
this.next = next;
}

}

Establishment list (Link.java)

package com.yz.mystack;

public class Link {
Node head;
public Link () {
head = new Node (null);
}
public void addNode (Node node) {
Node p = head;
node.setNext (p.getNext ());
p.setNext (node);

}
public void delNode () {
if (! isEmploy ()) {
head.setNext (head.getNext (). getNext ());
}
}

public Node gettop () {
return head.getNext ();
}
public Boolean isEmploy () {
return head.getNext () == null;
}
public void display () {
Node p = head;
while (true) {
p = p.getNext ();
if (p! = null) {
System.out.println (p.getData ());
} Else {
break;
}
}
}

}

Establishment of the stack

package com.yz.mystack;

public class Stack {
Link link;

public Stack () {
link = new Link ();
}
public void push (Object data) {
link.addNode (new Node (data));
}

public Object peek () {
return link.gettop (). getData ();
}
public Object pop () {
Object data = peek ();
link.delNode ();
return data;
}

}

相关文章
  • java data structure stack 2011-04-28

    Create node classes (Node.java) package com.yz.mystack; public class Node { Object data; Node next; public Node (Object data) { this.data = data; next = null; } public Object getData () { return data; } public void setData (Object data) { this.data =

  • JAVA data structure (change) 2010-05-25

    Linear table, linked list, hash table is a common data structure, making Java development time, JDK has provided us with a corresponding set of classes to implement basic data structures. These classes are in the java.util package. This paper attempt

  • java data structure five. Stack 2010-10-19

    <! - Generated by javadoc (build 1.6.0-beta2) on Fri Mar 09 12:52:21 CST 2007 -> Stack class represents a last in first out (LIFO) stack of objects. Through five operating java.util.Stack JDK in the class Vector is extended to allow the vector as a

  • java data structure VII. through the stack to convert infix expression to achieve a postfix expression 2010-10-20

    //infix.java //converts infix arithmetic expressions to postfix //to run this program: C>java InfixApp import java.io.*; // for I/O //////////////////////////////////////////////////////////////// class StackX { private int maxSize; private char[] st

  • Data Structure - Stack (1) 2010-06-07

    Linked to achieve the life of the stack ADT # Ifdef struct Node; typedef struct Node * PtrToNode; typedef PtrToNode Stack; int IsEmpty (Stack S); Stack CreateStack (void); void DisposeStack (Stack S); void MakeEmpty (Stack S); void Push (SlementType

  • JAVA data structure - simple matrix 2010-10-15

    Questions asked 5 12345 161,718,196 152,425,207 142,322,218 131,211,109 6 123,456 20212223247 19323334258 18313635269 173029282710 161514131211 package com.java.duncan; import java.io.BufferedInputStream; import java.util.Scanner; public class Matrix

  • Data structures: stack solve the maze _ 1 application 2010-10-11

    /************************************************* ***********************/ / * Data structures: stack applications: solving maze problems * / / * Burning the midnight oil to see the sword-shuchangs @ 126.com 2010-10 * / / * Song Yun International (C

  • Data structures: stack solve the maze _ 2 Application 2010-10-11

    /************************************************* ***********************/ / * Data structures: stack applications: solving maze problems * / / * Burning the midnight oil to see the sword-shuchangs @ 126.com 2010-10 * / / * Song Yun International (C

  • Data structures: stack solve the maze _ 3 applications 2010-10-11

    /************************************************* ***********************/ / * Data structures: stack applications: solving maze problems * / / * Burning the midnight oil to see the sword-shuchangs @ 126.com 2010-10 * / / * Song Yun International (C

  • Data structures: stack solve the Tower of Hanoi application _ (Hanoi) 1 2010-10-15

    /************************************************* ***********************/ / * Data structure: Stack Application: Tower of Hanoi (Hanoi) problem * / / * Burning the midnight oil to see the sword-shuchangs @ 126.com 2010-10 * / / * Song Yun Internati

  • Data structures: stack solve the Tower of Hanoi application _ (Hanoi) 2 2010-10-15

    /************************************************* ***********************/ / * Data structure: Stack Application: Tower of Hanoi (Hanoi) problem * / / * Burning the midnight oil to see the sword-shuchangs @ 126.com 2010-10 * / / * Song Yun Internati

  • Data Structure Java stack stack and queue Queue 2010-04-29

    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

  • Java, C, and the data structure in the data stack and heap 2010-10-04

    Java: http://hi.baidu.com/reset_87/blog/item/726afb08397acf2c6b60fbfc.html writes Basic data types directly in stack space allocation, method form parameters directly in the stack space allocation, when the method call is complete recovery from the s

  • ----- JAVA class set data structure learning of linear form ------- 2010-11-27

    The linear table data structure, corresponding to the Collection of the List interface. In this section, we will do the following three things First. Let's take a look at the characteristics of the linear form Second, their implementation with JAVA L

  • Change: Focus on Queue: Java 1.5 add a new data structure interface (SynchronousQueue) 2008-10-22

    Reprinted: http://blog.csdn.net/Victor_Jan/archive/2004/09/27/117695.aspx Java 1.5 versions will ultimately be provided for programming, one of the most basic data structure of the inner-Queue to support. This article will explore the newly added to

  • (F) the preparation of MP3 decoder using JAVA - Frame data structure 2010-08-19

    MP3 files stored by the frame sequence, the frame data structure as shown below: Frame header of each frame in turn kept (header), the frame side information (side information), the main information (main information). One of the main information by

  • Data structure: the basic operation stack 2010-10-11

    /************************************************* ***********************/ / * Data structure: basic operation of the stack: into the stack, the stack, print the stack * / / * Burning the midnight oil to see the sword-shuchangs @ 126.com 2010-10 * /

  • _ Stack data structure to achieve _Java 2011-05-20

    _ Stack data structure to achieve _Java First, the concept

  • ------- JAVA class set data structure learning ----- lookup table (Zong Lun) 2010-11-28

    Have been prepared to write an article on this one lookup table and found the content too much, so now the decision is divided into three parts. 1. The concept of look-up table 2. Static lookup table 3. Dynamic Lookup Table 4. Hash Table, and Map Thi

  • difference between java heap and stack 2010-05-13

    Java in the stack (stack) and heap (heap) of a stack (stack) and heap (heap)? (1) memory allocation strategy in accordance with the principles of the view compiler, runtime memory allocation, there are three strategies, namely, static, stack type, an