File tree Expand file tree Collapse file tree 12 files changed +26
-30
lines changed Expand file tree Collapse file tree 12 files changed +26
-30
lines changed Original file line number Diff line number Diff line change @@ -97,11 +97,6 @@ <h1 id="headerText">Heap Datastructure</h1>
97
97
Remove max
98
98
</ button >
99
99
< br />
100
- < button id ="buildHeap " class ="btn btn-primary " style ="display: none ">
101
- <!-- Click-Event handled in setUpBuildButton in methods.ts-->
102
- Convert to Heap
103
- </ button >
104
- < br />
105
100
< button id ="sortHeap " class ="btn btn-primary " style ="display: none ">
106
101
<!-- Click-Event handled in setUpSortButton in methods.ts-->
107
102
Sort using HeapSort
Original file line number Diff line number Diff line change @@ -25,9 +25,10 @@ var HeapSort = /** @class */ (function (_super) {
25
25
control . setArrow ( this . sortIndex ) ;
26
26
this . remove ( ) ;
27
27
}
28
+ control . setArrow ( - 1 ) ;
28
29
} ;
29
30
HeapSort . prototype . remove = function ( ) {
30
- // Remove root element, set last element to root and start frontendevents
31
+ // Switch root and last element, remove root and start frontendevents
31
32
var oldVal = this . array [ 0 ] ;
32
33
this . exch ( 0 , -- this . currIndex ) ;
33
34
control . sortHighlightTwoNodes ( this . currIndex , this . sortIndex , "orange" ) ;
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ class HeapSort extends MaxHeap {
18
18
control . setArrow ( this . sortIndex ) ;
19
19
this . remove ( ) ;
20
20
}
21
+ control . setArrow ( - 1 ) ;
21
22
}
22
23
23
24
remove ( ) : void {
Original file line number Diff line number Diff line change @@ -130,8 +130,17 @@ var MaxHeap = /** @class */ (function () {
130
130
var right = index * 2 + 2 ;
131
131
if ( left >= length )
132
132
return ;
133
- if ( this . array [ index ] >= this . array [ left ] && this . array [ index ] >= this . array [ right ] )
133
+ if ( this . array [ index ] >= this . array [ left ] && this . array [ index ] >= this . array [ right ] ) {
134
+ if ( this . array [ left ] >= this . array [ right ] || right >= length ) {
135
+ control . highlightTwoNodes ( index , left , "green" ) ;
136
+ control . removeHighlightTwoNodes ( index , left , "green" ) ;
137
+ }
138
+ else {
139
+ control . highlightTwoNodes ( index , right , "green" ) ;
140
+ control . removeHighlightTwoNodes ( index , right , "green" ) ;
141
+ }
134
142
return ;
143
+ }
135
144
// Sink
136
145
var other ;
137
146
if ( right >= length )
Original file line number Diff line number Diff line change @@ -151,8 +151,16 @@ class MaxHeap implements IAlgorithm {
151
151
152
152
if ( left >= length )
153
153
return ;
154
- if ( this . array [ index ] >= this . array [ left ] && this . array [ index ] >= this . array [ right ] )
154
+ if ( this . array [ index ] >= this . array [ left ] && this . array [ index ] >= this . array [ right ] ) {
155
+ if ( this . array [ left ] >= this . array [ right ] || right >= length ) {
156
+ control . highlightTwoNodes ( index , left , "green" )
157
+ control . removeHighlightTwoNodes ( index , left , "green" ) ;
158
+ } else {
159
+ control . highlightTwoNodes ( index , right , "green" ) ;
160
+ control . removeHighlightTwoNodes ( index , right , "green" ) ;
161
+ }
155
162
return ;
163
+ }
156
164
157
165
// Sink
158
166
let other ;
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ var MaxHeapCombined = /** @class */ (function (_super) {
36
36
control . setArrow ( this . sortIndex ) ;
37
37
this . remove ( ) ;
38
38
}
39
+ control . setArrow ( - 1 ) ;
39
40
} ;
40
41
MaxHeapCombined . prototype . remove = function ( ) {
41
42
// Switch root and last element, remove root and start frontendevents
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ class MaxHeapCombined extends MaxHeapFree {
29
29
control . setArrow ( this . sortIndex ) ;
30
30
this . remove ( ) ;
31
31
}
32
+ control . setArrow ( - 1 ) ;
32
33
}
33
34
34
35
remove ( ) : void {
Original file line number Diff line number Diff line change @@ -180,10 +180,8 @@ var View = /** @class */ (function () {
180
180
control . removeNode ( ) ;
181
181
} ;
182
182
View . prototype . sortHeap = function ( ) {
183
- control . sortHeap ( ) ;
184
- } ;
185
- View . prototype . buildHeap = function ( ) {
186
183
control . buildHeap ( ) ;
184
+ control . sortHeap ( ) ;
187
185
} ;
188
186
View . prototype . swapNode = function ( child , parent ) {
189
187
var forward = function ( child , parent ) {
Original file line number Diff line number Diff line change @@ -207,13 +207,10 @@ class View {
207
207
}
208
208
209
209
sortHeap ( ) {
210
+ control . buildHeap ( ) ;
210
211
control . sortHeap ( ) ;
211
212
}
212
213
213
- buildHeap ( ) {
214
- control . buildHeap ( ) ;
215
- }
216
-
217
214
swapNode ( child : number , parent : number ) {
218
215
let forward = function ( child , parent ) {
219
216
return function ( ) {
Original file line number Diff line number Diff line change @@ -16,7 +16,6 @@ var GraphNode = /** @class */ (function () {
16
16
this . moveBothDirections ( xLayer * 70 , yLayer * 50 , time ) ;
17
17
return xLayer + 1 ;
18
18
}
19
- // Recursive
20
19
else {
21
20
for ( var _i = 0 , _a = this . children ; _i < _a . length ; _i ++ ) {
22
21
var child = _a [ _i ] ;
Original file line number Diff line number Diff line change @@ -312,12 +312,6 @@ function setUpRemoveButton() {
312
312
} ) ;
313
313
}
314
314
setUpRemoveButton ( ) ;
315
- function setUpBuildButton ( ) {
316
- $ ( "#buildHeap" ) . click ( function ( ) {
317
- viewer . buildHeap ( ) ;
318
- } ) ;
319
- }
320
- setUpBuildButton ( ) ;
321
315
function setUpSortButton ( ) {
322
316
$ ( "#sortHeap" ) . click ( function ( ) {
323
317
viewer . sortHeap ( ) ;
Original file line number Diff line number Diff line change @@ -360,14 +360,6 @@ function setUpRemoveButton() {
360
360
361
361
setUpRemoveButton ( ) ;
362
362
363
- function setUpBuildButton ( ) {
364
- $ ( "#buildHeap" ) . click ( function ( ) {
365
- viewer . buildHeap ( ) ;
366
- } ) ;
367
- }
368
-
369
- setUpBuildButton ( )
370
-
371
363
function setUpSortButton ( ) {
372
364
$ ( "#sortHeap" ) . click ( function ( ) {
373
365
viewer . sortHeap ( ) ;
You can’t perform that action at this time.
0 commit comments