Advertisement
jtentor

DemoQueue4 - SpecialQueue.java

May 17th, 2020
538
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class SpecialQueue<ELEMENT> extends java.util.ArrayDeque<ELEMENT> {
  2.  
  3.     public SpecialQueue() {
  4.         this(10);
  5.     }
  6.  
  7.     public SpecialQueue(int capacity) {
  8.         super(capacity);
  9.     }
  10.  
  11.     public SpecialQueue<ELEMENT> join(SpecialQueue<ELEMENT> other) {
  12.         SpecialQueue<ELEMENT> result =
  13.                 new SpecialQueue<ELEMENT>((this.size() + other.size()) * 2);
  14.  
  15.         ELEMENT[] data = (ELEMENT[]) this.toArray();
  16.         for (ELEMENT e : data) {
  17.             result.add(e);
  18.         }
  19.  
  20.         data = (ELEMENT[]) other.toArray();
  21.         for (ELEMENT e : data) {
  22.             result.add(e);
  23.         }
  24.  
  25.         return result;
  26.     }
  27.  
  28. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement