标签:code array last class pac div rgs over exti
1 //给出队接口的定义,然后基于List接口及其实现类给出队的两种实现类(采用ArrayList和LinkkedList 2 //实现分别给出队的实现类) 3 package classwork9; 4 5 public interface Dui { 6 public abstract void push(); 7 public abstract void pop(); 8 } 9 package classwork9; 10 11 import java.util.ArrayList; 12 import java.util.List; 13 import java.util.Scanner; 14 15 public class Duiarray implements Dui { 16 17 List<Double> a=new ArrayList<Double>(); 18 Scanner in=new Scanner(System.in); 19 @Override 20 public void push() { 21 System.out.println("请输入入队元素:"); 22 double x=in.nextDouble(); 23 a.add(x); 24 } 25 26 @Override 27 public void pop() { 28 System.out.println("出队元素为:"+a.get(0)); 29 a.remove(0); 30 31 } 32 33 } 34 package classwork9; 35 36 public class DuiarrayTest { 37 public static void main(String[] args) { 38 Duiarray a=new Duiarray(); 39 a.push(); 40 a.push(); 41 a.push(); 42 a.pop(); 43 a.pop(); 44 } 45 } 46 package classwork9; 47 48 import java.util.LinkedList; 49 import java.util.List; 50 import java.util.Scanner; 51 52 public class Duilink implements Dui { 53 54 List<Integer> a=new LinkedList<Integer>(); 55 Scanner in=new Scanner(System.in); 56 @Override 57 public void push() { 58 System.out.println("请输入入队元素:"); 59 int x=in.nextInt(); 60 ((LinkedList<Integer>) a).addFirst(x); 61 } 62 63 @Override 64 public void pop() { 65 System.out.println("出队元素为:"+((LinkedList<Integer>) a).getLast()); 66 ((LinkedList<Integer>) a).removeLast(); 67 68 } 69 70 } 71 package classwork9; 72 73 public class DuilinkTest { 74 75 public static void main(String[] args) { 76 Duilink a=new Duilink(); 77 a.push(); 78 a.push(); 79 a.push(); 80 a.pop(); 81 a.pop(); 82 } 83 84 }
//给出队接口的定义,然后基于List接口及其实现类给出队的两种实现类(采用ArrayList和LinkkedList //实现分别给出队的实现类)
标签:code array last class pac div rgs over exti
原文地址:https://www.cnblogs.com/dss-99/p/14124991.html