`

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...

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

    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 ...

    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 ...

    Beginning Python (2005).pdf

    Running a Module as a Program 164 Try It Out: Running a Module 164 Creating a Whole Module 165 Try It Out: Finishing a Module 165 Try It Out: Smashing Imports 169 Installing Your Modules 170 Try...

    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,...

    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: ...

    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...

    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 ...

    Thinking in Java 4th Edition

    Building a Java program ...... 50 Name visibility ............................. 50 Using other components ............. 50 The static keyword ..................... 51 Your first Java program ....... ...

    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