1 package com.gxf.collection; 2 3 import java.util.LinkedList; 4 5 public class TestForT{ 6 private LinkedList storage = new LinkedList (); 7 8 /** 9 * 压栈操作10 * @param element11 */12 public void push(T element){13 storage.addFirst(element);14 }15 /**16 * 出栈17 * @return18 */19 public T pop(){20 return storage.removeFirst();21 }22 23 /**24 * 判断栈是否为空25 * @return26 */27 public boolean isEmpty(){28 return storage.isEmpty();29 }30 31 public static void main(String[] args) {32 TestForT stack = new TestForT ();33 stack.push(1);34 stack.push(2);35 stack.push(3);36 stack.push(4);37 stack.push(5);38 39 while(!stack.isEmpty()){40 System.out.println(stack.pop());41 }42 }43 44 }
output:
5
4321