标签:
1 package com.shb.java; 2 3 import java.util.LinkedList; 4 5 public class TestLinkedList { 6 7 /** 8 * @author shaobn 9 * @Describe :利用LinkedList实现队列和堆栈 10 * @param args 11 * @Time : 2015-8-27 下午10:28:33 12 */ 13 public static void main(String[] args) { 14 // TODO Auto-generated method stub 15 DoLinkedList dll = new DoLinkedList(); 16 String []str = {"java","php","C","C++"}; 17 testAdd(dll, str); 18 while(!testEmp(dll)){ 19 sysMethod(testGet(dll)); 20 } 21 System.out.println("执行完毕"); 22 } 23 24 public static void sysMethod(Object obj){ 25 26 System.out.println(obj); 27 } 28 public static void testAdd(DoLinkedList dll,String[] str){ 29 for(String s:str){ 30 dll.addEle(s); 31 } 32 } 33 public static String testGet(DoLinkedList dll){ 34 return dll.getEle(); 35 } 36 public static boolean testEmp(DoLinkedList dll){ 37 if(dll.isEmp()){ 38 return true; 39 }else { 40 return false; 41 } 42 } 43 } 44 class DoLinkedList{ 45 private LinkedList<String> linkedList; 46 public DoLinkedList(){ 47 this.linkedList = new LinkedList<String>(); 48 } 49 public void addEle(String str){ 50 51 linkedList.add(str); 52 } 53 public String getEle(){ 54 return linkedList.removeFirst(); 55 } 56 public boolean isEmp(){ 57 return linkedList.isEmpty(); 58 59 } 60 }
一个简单的小程序,封装的不太好,半夜写的,如有错误,欢迎大家指出,谢谢。
标签:
原文地址:http://www.cnblogs.com/assassin666/p/4765413.html