jtentor icon

DemoQueue4 - SpecialQueue.java

jtentor | PRO | 05/17/20 03:35:54 PM UTC | 0 ⭐ | 848 👁️ | Never ⏰ | []
Java |

670 B

|

None

|

0 👍

/

0 👎

public class SpecialQueue<ELEMENT> extends java.util.ArrayDeque<ELEMENT> {
 
    public SpecialQueue() {
        this(10);
    }
 
    public SpecialQueue(int capacity) {
        super(capacity);
    }
 
    public SpecialQueue<ELEMENT> join(SpecialQueue<ELEMENT> other) {
        SpecialQueue<ELEMENT> result =
                new SpecialQueue<ELEMENT>((this.size() + other.size()) * 2);
 
        ELEMENT[] data = (ELEMENT[]) this.toArray();
        for (ELEMENT e : data) {
            result.add(e);
        }
 
        data = (ELEMENT[]) other.toArray();
        for (ELEMENT e : data) {
            result.add(e);
        }
 
        return result;
    }
 
}

Comments