Java链栈
2024-10-15 11:51:58
package com.lxm.customDataStructure;
public class LinkStack<T>{
class Node<T>{
T data;
Node next;
Node(T data)
{
this.data=data;
this.next = null;
}
}
Node<T> head;
public LinkStack(T data)
{
this.head = null;
}
public boolean isEmpty()
{
return this.head==null;
}
public void push(T e)
{
Node temp = new Node(e);
temp.next = this.head;
this.head = temp;
}
public T pop()
{
if(this.isEmpty()) return null;
Node temp = this.head;
this.head = temp.next;
return (T) temp.data;
}
public static void main(String[] args)
{
LinkStack<Integer> S = new LinkStack<Integer>(0);
for(int i=0;i<10;i++)
{
S.push(i+1);
}
while(S.isEmpty()==false)
{
System.out.print(S.pop()+"\t");
}
System.out.println();
}
}
最新文章
- tftp 限制ip 限制ip段 或者多个ip段访问
- 使用Apache Commons Configuration读取配置信息
- pgadmin中的备份功能消失的原因和找回方法
- MYSQL校对规则
- Android优化——UI优化(二) 使用include标签复用布局
- python string与list互转
- Unity GUI内绘制贝塞尔曲线
- List<;T>;Contains, Exists, Any之间的优缺点对比
- 在 Asp.NET MVC 中使用 SignalR 实现推送功能
- String 、InputStream、Reader 的转换
- 使用内核定时器的second字符设备驱动及测试代码
- LINQ 101——约束、投影、排序
- htm5 user-scalable 的意思
- Linux下一个patch补丁命令
- 黑科技--位集--bitset
- android 如何画心
- 注解式controller开发,action找不到controller???
- Linux下的压缩和解压缩命令gzip/gunzip
- hdu 1576 A/B 【扩展欧几里得】【逆元】
- sql(Oracle)优化之索引
热门文章
- [ jquery 过滤器 hasClass(class) ] 此方法用于在选择器的基础之上检查当前的元素是否含有某个特定的类,如果有,则返回true
- SQL性能优化案例分析
- 谈谈Fragment中的onActivityResult
- 通过jconsole监控tomcat JVM 内存、线程、CPU
- 错误解决:error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory
- .net 已知图片的网络路径,通过浏览器下载图片
- C#:枚举
- .NET架构设计、框架设计系列文章总结
- 查看SQLserver编码格式的SQL语句
- fetch_20newsgroups 数据集导入失败: no handlers could be fetch_20newsgroups