`

Use Queue as a Stack

    博客分类:
  • java
阅读更多
package com.zhoubo.concurrent.collection;

import java.util.LinkedList;
/**
 * 用linkedList实现stack(LIFO)
 * @author Administrator
 *
 */
public class QStack {
	public  LinkedList<String> stack = new LinkedList<String>();
	
	public void add(String str){
		stack.add(str);
	}
	
	public String pop(){
		return stack.removeLast();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		QStack qStack = new QStack();
		qStack.stack.add("jim");
		qStack.stack.add("lily");
		qStack.stack.add("lucy");
		System.out.println(qStack.pop());
		System.out.println(qStack.pop());
		System.out.println(qStack.pop());
		
	}

}

 

分享到:
评论

相关推荐

    Swift Data Structure and Algorithms [2016]

    Find out about Swift generators and sequences, and see how to use them to implement advanced data structures such as Stack, StackList, Queue, and LinkedList Implement sorting algorithms such as ...

    Learning.JavaScript.Data.Structures.and.Algorithms.1783554878

    This book begins by covering the basics of the JavaScript language and then moves on to discuss the most important data structures such as array, queue, stack, and linked list. You will also gain an ...

    Swift.Data.Structure.and.Algorithms

    oriented programming Find out about Swift generators and sequences, and see how to use them to implement advanced data structures such as Stack, StackList, Queue, and LinkedList Implement sorting ...

    计算机网络第六版答案

    (This is a little bit of a white lie, as modern routers sometimes act as firewalls or caching components, and process Transport layer as well.) Link layer switches process link and physical layers ...

    Problem Solving in Data Structures & Algorithms Using Java, 2nd

    We will be looking into a Linked-List, Stack, Queue, Trees, Heap, Hash-Table and Graphs. We will also be looking into Sorting, Searching techniques. In last few chapters, we will be looking into ...

    Java 9 Data Structures and Algorithms

    Get a grasp on the basics of abstract data types—stack, queue, and double ended queue See how to use recursive functions and immutability while understanding and in terms of recursion Handle reactive...

    C & C++ Win32 API Programming

    - **Message Queue**: Windows maintains a message queue for each thread. Messages are placed in the queue and retrieved by the message loop. - **Message Loop**: The message loop retrieves messages from...

    CE中文版-启点CE过NP中文.exe

    Pointerscan for value scans now add the results to the overflow queue Opening a file and changing bytes do not change them to the file anymore (you need to explicitly save now) Added an option to the ...

    acpi控制笔记本风扇转速

    code size, and reduces CPU stack use. (Valery Podrezov + interpreter changes in version 20051202 that eliminated namespace loading during the pass one parse.) Implemented _CID support for PCI Root ...

    VB编程资源大全(英文源码 函数)

    &lt;END&gt;&lt;br&gt;11,Recursion.zip A VB application which demonstrates Recursion.&lt;END&gt;&lt;br&gt;12,StacksQs.zip The Stack and Queue data structures are presented in this VB application. &lt;END&gt;&lt;br&gt;13,...

    The Art of Assembly Language Programming

    The 886 Processor 3.3.11 - The 8286 Processor 3.3.12 - The 8486 Processor 3.3.12.1 - The 8486 Pipeline 3.3.12.2 - Stalls in a Pipeline 3.3.12.3 - Cache, the Prefetch Queue, and the ...

    python3.6.5参考手册 chm

    PEP 3105: print As a Function PEP 3110: Exception-Handling Changes PEP 3112: Byte Literals PEP 3116: New I/O Library PEP 3118: Revised Buffer Protocol PEP 3119: Abstract Base Classes PEP 3127: ...

    2021-2022计算机二级等级考试试题及答案No.3873.docx

    2. SQL的`DELETE`命令可以直接删除数据库表中的记录,但在Visual FoxPro中,使用SQL命令删除记录前需先用`USE`命令打开表,这是对数据库操作的基本规则。而传统的Visual FoxPro `DELETE`命令则是直接对当前打开的表...

    C++标准库(第二版)英文版.pdf

    The C++ Standard Library A Tutorial and Reference (2nd Edition)+cppstdlib-code.zip C++标准库(第二版)英文版.pdf 非扫描版+源代码 Prefaceto the SecondEdition xxiii Acknowledgments for the Second...

    Making Games with Python & PyGame.pdf(with code)

    How to Use This Book ................................................................................................................. 4 The Featured Programs ............................................

    C#全能速查宝典

    1.1.2 as操作符——引用类型转换 3 1.1.3 base关键字——从派生类中访问基类的成员 3 1.1.4 变量——存储特定类型的数据 4 1.1.5 Console类——控制台中的输入流、输出流和错误流 6 1.1.6 Convert类——类型转换 8 ...

Global site tag (gtag.js) - Google Analytics