package hashMap;
import java.util.ArrayList;
import d.Student;
/**
* 用ArrayList模拟栈操作
* @author zhujiabin
* @see 2016年7月14日
*/ public class Stack
{
ArrayList<Student> al=new ArrayList<Student>();
public Object peek()
{
return al.get();
}
public Object pop()//出栈
{
return al.remove(al.size()-);
}
public void push(Student o)//进栈
{
al.add(o);
}
public void clear()//将栈置空
{
al.clear();
}
public boolean isEmpty()//判断栈是否是空
{
if(al.isEmpty())
{
return true;
}
else
{
return false;
}
}
public Object getIndex(int i)//返回指定下标出的值
{
return al.get(i);
}
}

测试:

package hashMap;
import d.Student;
/**
* 用ArrayList模拟栈操作
* @author 郑云飞
* @see 2010年8月14日
*/
public class StackTest
{
public static void main(String[] args)
{
Stack s1=new Stack();
s1.push(new Student("庄子",));
s1.push(new Student("老子",));
s1.push(new Student("梦子",));
s1.push(new Student("荀子",));
while(!s1.isEmpty())
{
System.out.println(s1.pop());//出栈输出内容
} }
} package hashMap;
/**
* 用ArrayList模拟栈操作
* @author zhujiabin
* @see 2016年7月14日
*/
public class Student
{
String name;
int age;
public Student(String name,int age)
{
this.name=name;
this.age=age;
}
public String toString()
{
return "姓名:" +name+"年龄:"+age;
}
}

最新文章

  1. vs2012相关配置
  2. HBase 安装过程记录
  3. 对象属性操作-包含kvc---ios
  4. URAL 1066 Garland 二分
  5. 通过maven添加quartz
  6. ubuntu安装hadoop2.6
  7. JQuery插件的学习
  8. UML(Unified Modeling Language)同一建模语言
  9. SQL进阶随笔--case用法(二)
  10. 你应该知道的 volatile 关键字
  11. python 试题
  12. Hadoop项目实战-用户行为分析之应用概述(三)
  13. C语言 &#183; 算年龄
  14. linux常用命令:df 命令
  15. [原][译][osg][osgEarth]飞行模拟软件JSBSim的操作(FGFCS类)
  16. 润乾报表JSF FORM 标签中使用填报表解决方案
  17. HDU 5154 Harry and Magical Computer bfs
  18. poj1228 Grandpa&#39;s Estate
  19. php 实现重定向的三种方式
  20. redis基础之redis-cluster(集群)(七)

热门文章

  1. Unity3D 之UGUI 切换开关(toggle)
  2. ASP.net程序在本地操作正确,新电脑不正确的处理经验
  3. O-C-11-利用类方法做一个简单的计算器
  4. asp.net:repeater嵌套(常用于新闻等在首页归类显示)
  5. caffe源码阅读(3)-Datalayer
  6. android软件开发之webView.addJavascriptInterface循环渐进【一】
  7. python 在调用时计算默认值
  8. variable-precision SWAR算法:计算Hamming Weight
  9. 身份证js验证
  10. REST接口规范