    }

    function checkHeap(heap) {
      try {
        heap.checkIntegrity();
        let last = null;
        let report = "";
        for (let k = 0; k < n; k++) {
          const a = heap.remove();
          report += k + ": " + JSON.stringify(a) + "\n";
          if (last != null && less(a, last)) {
            throw "Error: " + JSON.stringify(a) + " < " + JSON.stringify(last);
          }
          last = a;
        }
        return report;
      } catch (e) {
        document.getElementById("error"