• Java实现栈和队列



    <pre name="code" class="java">import java.util.LinkedList;
    
    /**栈的定义*/
    public class Stack<T> {
    	/**定义栈的存储结构。LinkedList*/
    	private LinkedList<T> storage = new LinkedList<T>();
    	
    	/**压栈操作*/
    	public void push(T t){storage.addFirst(t); }
    	
    	/**获取栈顶元素*/
    	public T getTop() {return storage.getFirst(); }
    	
    	/**出栈操作*/
    	public T pop() {return storage.removeFirst(); }
    	
    	/**推断栈是否为空*/
    	public boolean isEmpty() {return storage.isEmpty(); }
    	
    	/**打印栈中的元素*/
    	public String toString() {return storage.toString(); } 
    	
    }
    

    
    

    import java.util.LinkedList;
    
    /**队列的定义*/
    public class Queue<T> {
    
    	/**定义队列的存储结构,LinkedList*/
    	private LinkedList<T> storage = new LinkedList<T>();
    	
    	/**进队操作*/
    	public void push(T t) {storage.addLast(t);}
    	
    	/**获取队首元素*/
    	public T getHead() {return storage.getFirst();}
    	
    	/**出队操作*/
    	public T pop(){return storage.removeFirst();}
    	
    	/**推断队列是否为空*/
    	public boolean isEmpty() {return storage.isEmpty();}
    	
    	/**打印队列元素*/
    	public String toString(){return storage.toString();}
    }



  • 相关阅读:
    历届试题 大臣的旅费
    JQuery UI的拖拽功能
    JQuery UI的拖拽功能
    jQuery.extend 函数详解
    jQuery.extend 函数详解
    javax.servlet.http.httpservlet is not defined
    javax.servlet.http.httpservlet is not defined
    RESTful Web Services
    RESTful Web Services
    oracle创建一个一般用户
  • 原文地址:https://www.cnblogs.com/llguanli/p/6780387.html
Copyright © 2020-2023  润新知