|
| 1 | +/** |
| 2 | + * Created by Øyvind Skeie Liland on 13.03.18 |
| 3 | + */ |
| 4 | +var __extends = (this && this.__extends) || (function () { |
| 5 | + var extendStatics = Object.setPrototypeOf || |
| 6 | + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
| 7 | + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; |
| 8 | + return function (d, b) { |
| 9 | + extendStatics(d, b); |
| 10 | + function __() { this.constructor = d; } |
| 11 | + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
| 12 | + }; |
| 13 | +})(); |
| 14 | +///<reference path="methods.ts"/> |
| 15 | +///<reference path="drawGraph.ts"/> |
| 16 | +var MaxHeapCombined = /** @class */ (function (_super) { |
| 17 | + __extends(MaxHeapCombined, _super); |
| 18 | + function MaxHeapCombined(size) { |
| 19 | + var _this = _super.call(this, size) || this; |
| 20 | + HeapSort.insertElems(10); |
| 21 | + _this.sortIndex = _this.currIndex - 1; |
| 22 | + return _this; |
| 23 | + } |
| 24 | + MaxHeapCombined.prototype.add = function (a) { |
| 25 | + this.sortIndex++; |
| 26 | + if (this.currIndex > 10) { |
| 27 | + return; |
| 28 | + } |
| 29 | + else { |
| 30 | + this.array[this.currIndex] = a; |
| 31 | + control.insertNewElem(this.currIndex++, a, Math.floor((this.currIndex - 2) / 2)); |
| 32 | + } |
| 33 | + }; |
| 34 | + MaxHeapCombined.prototype.sort = function () { |
| 35 | + for (var i = this.sortIndex; i >= 0; i--) { |
| 36 | + control.setArrow(this.sortIndex); |
| 37 | + this.remove(); |
| 38 | + } |
| 39 | + }; |
| 40 | + MaxHeapCombined.prototype.remove = function () { |
| 41 | + // Switch root and last element, remove root and start frontendevents |
| 42 | + var oldVal = this.array[0]; |
| 43 | + this.exch(0, --this.currIndex); |
| 44 | + control.sortHighlightTwoNodes(this.currIndex, this.sortIndex, "orange"); |
| 45 | + control.setSortValAndDeselect(this.sortIndex, oldVal); |
| 46 | + control.removeElem(this.currIndex, false); |
| 47 | + this.sink(0, this.currIndex); |
| 48 | + control.highlightSortElem(this.sortIndex--, "green"); |
| 49 | + }; |
| 50 | + MaxHeapCombined.prototype.getName = function () { |
| 51 | + return "MaxHeapCombined"; |
| 52 | + }; |
| 53 | + return MaxHeapCombined; |
| 54 | +}(MaxHeapFree)); |
0 commit comments