public class LinkedStack<T> {

    private static class Node<U>{
U item;
Node<U>next;
Node(){
item=null;
next=null;
}
Node(U u,Node<U>node){
item=u;
next=node;
}
boolean end(){
return item==null&&next==null;
}
}
private Node<T>top=new Node<T>();
public void push(T item){
top=new Node<T>(item,top);
} public T pop(){
T result=top.item;
if(!top.end()){
top=top.next;
}
return result;
}
public static void main(String[] args) {
LinkedStack<String> ls=new LinkedStack<String>(); for(String s:"this is code test!!".split(" ")){
ls.push(s);
}
String s;
while ((s=ls.pop())!=null){
System.out.println(s);
} }
}

  

LinkedStack的更多相关文章

  1. LinkedStack<T>

    public class LinkedStack<T> { private static class Node<U> { U item; Node<U> next; ...

  2. 第五周作业总结(内含用Junit测试ArrayStack和LinkedStack课堂练习报告)

    ---恢复内容开始--- 学号 20162310<程序设计与数据结构>第五周学习总结 教材学习内容总结 集合分为线性集合(集合中的元素排成一行)和非线性集合(按不同于一行的方式来组织元素, ...

  3. LinkedStack的底层实现

    package zy813ture; import java.util.EmptyStackException; public class MyLinkedStack1 { private Node ...

  4. 栈的JS实现

    栈,是一种特殊的线性表,其插入及删除的操作都在线性表的同一端进行.这一端称为栈顶,另一端称为栈底.就类似于餐厅里的一摞盘子,后放的盘子在上方,也会先被人拿走.栈具有"后进先出"的逻 ...

  5. JAVA 内部类 泛型 实现堆栈

    堆栈类: package c15; public class LinkedStack<T> { private static class Node<T> { T item ; ...

  6. 用JAVA写简单的栈

    package com.gailekesi.example.expl_tuple; import javax.naming.NameNotFoundException; import java.awt ...

  7. Java学习注意事项

    一个Java文件中可以包含多个类. 如果有public类,则文件名必须和public类一样. 例如: class Pie { void f(){ System.out.println("Pi ...

  8. Thinking in Java from Chapter 15

    From Thinking in Java 4th Edition. 泛型实现了:参数化类型的概念,使代码可以应用于多种类型.“泛型”这个术语的意思是:“适用于许多许多的类型”. 如果你了解其他语言( ...

  9. 不用synchronized块的话如何实现一个原子的i++?

    上周被问到这个问题,没想出来,后来提示说concurrent包里的原子类.回来学习一下. 一.何谓Atomic? Atomic一词跟原子有点关系,后者曾被人认为是最小物质的单位.计算机中的Atomic ...

随机推荐

  1. Linux基础之常用命令整理(一)

    Linux 操作系统的安装 如今比较流线的linux操作系统 Centos Redhat  Fedora Ubuntu, 安装操作系统的提前是要有操作系统的镜像文件(.iso文件)并且必须为系统指定一 ...

  2. 在做MVC和WebApi写返回数据时,可以这样定义

    public class Messages { /// <summary> /// 返回包含是否成功以及消息字符结果 /// </summary> /// <param ...

  3. 【Python爬虫】01:网络爬虫--规则

    Python网络爬虫与信息提取 目标:掌握定向网络数据爬取和网页解析的基本能力. the website is the API 课程分为以下部分: 1.requsets库(自动爬取HTML页面.自动网 ...

  4. Source Insight 4.0安装后首次打开报错Unable to open or create

    错误提示大概如下: Unable to open or create ....我的文档/source insght4.0/xxx.sidb. 这个错误提示就是找不到这个文件,原因是应为有中文路径,那么 ...

  5. RN-入门基础

    Props State 一切界面变化,都是state变化 state修改必须通过setState方法 this.state.like=true 这样复制无效 setState是一个merge合并的操作 ...

  6. koa-passport实现本地验证

    安装 yarn add koa-passport passport-local 先看下passport.js登录策略,判断用户和密码 const passport = require('koa-pas ...

  7. Quick Search Articles in My Blog

    === Quickly Search Articles in My Blog: === 本文介绍了如何快速在主流搜索引擎搜索本专栏内文章的方法. Use Google's Search :  pres ...

  8. 71.纯 CSS 创作一个跳 8 字型舞的 loader

    原文地址:https://segmentfault.com/a/1190000015534639#articleHeader0 感想:rotateX() 和rotateZ()一起使用好懵呀. HTML ...

  9. Go 语言 map (映射)

    1.Go 语言中 map 的定义及初始化: map[Key_Type]Value_Type scence := make(map[string]int) 2.Go 语言的遍历: scene := ma ...

  10. node-服务器

    原生: const http=require('http'); http.createServer((request,response)=>{ response.writeHead(200,{& ...