public QueueNode pop() {
        if (this.isEmpty()) return null;
        QueueNode result = this.peek();
        int p = 0, p1, p2, pn;
        this.innerList.set(0, this.innerList.get(this.innerList.size()-1));
        this.innerList.remove(this.innerList.size()-1);
        this.nodeIDs.set(result.getNodeID(), -1);
        if (this.isEmpty()) return result;
        this.nodeIDs.set(this.innerList.get(0).getNodeID(), 0);
        while (true) {
            pn = p;
            p1 = 2*p+1;
            p2 = 2*p+2;
            if (this.innerList.size() > p1 && this.compareNodes(p, p1) > 0) p = p1;
            if (this.innerList.size() > p2 && this.compareNodes(p, p2) > 0) p = p2;
            if (p == pn) break;
            this.switchNodes(p, pn);
        }
        return result;
    }