ITPub博客

首页 > 应用开发 > IT综合 > Stack(v0.1) (转)

Stack(v0.1) (转)

原创 IT综合 作者:amyz 时间:2007-11-07 17:44:10 0 删除 编辑
Stack(v0.1) (转)[@more@]intelliJ_ideA_Html name=KEYwordS>

未定稿


array stack uml


 


1 package org.spring.ds.arraystack; 2 3 /** 4 * Created by IntelliJ IDEA. 5 * User: chunyang 6 * Date: 2003-6-20 7 * Time: 15:35:22 8 * Develop with pleasure!. 9 * Array based stack class 10 */ 11 public class MyArrayStack { 12 //Array holding stack objects 13 protected Object[] array; 14 //Index for top Object 15 protected int top;


16 17 public MyArrayStack(int size) { 18 array = new Object[size]; 19 top = -1; 20 }
21 22 public boolean isEmpty() { 23 return top == -1; 24 }
25 /** 26 * Push object onto stack 27 * @param o 28 */ 29 public void push(Object obj) { 30 if (top + 1 < array.length) 31 array[++top] = obj; 32 }
33 34 /** 35 * Pop object from top of stack 36 * @return 37 */ 38 public Object pop() { 39 if (isEmpty()) 40 return null; 41 return array[top--]; 42 }
43 44 45 /** 46 *Remove all objects from stack 47 */ 48 public void clear() { 49 top = -1; 50 } 51 }//class MyArrayStack 52

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752019/viewspace-981170/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    3984
  • 访问量
    7334687