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>
9797 Remove max
9898 </ button >
9999 < 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 />
105100 < button id ="sortHeap " class ="btn btn-primary " style ="display: none ">
106101 <!-- Click-Event handled in setUpSortButton in methods.ts-->
107102 Sort using HeapSort
Original file line number Diff line number Diff line change @@ -25,9 +25,10 @@ var HeapSort = /** @class */ (function (_super) {
2525 control . setArrow ( this . sortIndex ) ;
2626 this . remove ( ) ;
2727 }
28+ control . setArrow ( - 1 ) ;
2829 } ;
2930 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
3132 var oldVal = this . array [ 0 ] ;
3233 this . exch ( 0 , -- this . currIndex ) ;
3334 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 {
1818 control . setArrow ( this . sortIndex ) ;
1919 this . remove ( ) ;
2020 }
21+ control . setArrow ( - 1 ) ;
2122 }
2223
2324 remove ( ) : void {
Original file line number Diff line number Diff line change @@ -130,8 +130,17 @@ var MaxHeap = /** @class */ (function () {
130130 var right = index * 2 + 2 ;
131131 if ( left >= length )
132132 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+ }
134142 return ;
143+ }
135144 // Sink
136145 var other ;
137146 if ( right >= length )
Original file line number Diff line number Diff line change @@ -151,8 +151,16 @@ class MaxHeap implements IAlgorithm {
151151
152152 if ( left >= length )
153153 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+ }
155162 return ;
163+ }
156164
157165 // Sink
158166 let other ;
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ var MaxHeapCombined = /** @class */ (function (_super) {
3636 control . setArrow ( this . sortIndex ) ;
3737 this . remove ( ) ;
3838 }
39+ control . setArrow ( - 1 ) ;
3940 } ;
4041 MaxHeapCombined . prototype . remove = function ( ) {
4142 // 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 {
2929 control . setArrow ( this . sortIndex ) ;
3030 this . remove ( ) ;
3131 }
32+ control . setArrow ( - 1 ) ;
3233 }
3334
3435 remove ( ) : void {
Original file line number Diff line number Diff line change @@ -180,10 +180,8 @@ var View = /** @class */ (function () {
180180 control . removeNode ( ) ;
181181 } ;
182182 View . prototype . sortHeap = function ( ) {
183- control . sortHeap ( ) ;
184- } ;
185- View . prototype . buildHeap = function ( ) {
186183 control . buildHeap ( ) ;
184+ control . sortHeap ( ) ;
187185 } ;
188186 View . prototype . swapNode = function ( child , parent ) {
189187 var forward = function ( child , parent ) {
Original file line number Diff line number Diff line change @@ -207,13 +207,10 @@ class View {
207207 }
208208
209209 sortHeap ( ) {
210+ control . buildHeap ( ) ;
210211 control . sortHeap ( ) ;
211212 }
212213
213- buildHeap ( ) {
214- control . buildHeap ( ) ;
215- }
216-
217214 swapNode ( child : number , parent : number ) {
218215 let forward = function ( child , parent ) {
219216 return function ( ) {
Original file line number Diff line number Diff line change @@ -16,7 +16,6 @@ var GraphNode = /** @class */ (function () {
1616 this . moveBothDirections ( xLayer * 70 , yLayer * 50 , time ) ;
1717 return xLayer + 1 ;
1818 }
19- // Recursive
2019 else {
2120 for ( var _i = 0 , _a = this . children ; _i < _a . length ; _i ++ ) {
2221 var child = _a [ _i ] ;
You can’t perform that action at this time.
0 commit comments