data structures - How do I modify the Min Heap insert and delete function to accept a second comparison if the primary comparison happens to be equal? -
Below I put a standard for the minimum stack and delete the function, what I need to do is make a special case in both Add function when T.num comparisons are the same, then I get t. Letter should compare where the lower esque value pops for the first time. Enter the standard without comments and delete, adding the commented section will try to add my new feature, which for my life, I do not understand why this will not work.
zero MinHeap & lt; T & gt; :: insert (T & A) {int CurrNode = ++ HeapSize; While (CurrNode! = 1 & amp; amp; amp; heap [CurrNode / 2] .num> = e.num) {/ * ([CurrNode / 2] .num == e.num if (pile [ CurrNode / 2] .letter and lt; = e.letter) break; * / Hep [kernel node] = heap [kernel node / 2]; Cornnode / = 2; } Stack [CurrNode] = E; } Zero MinHeap & lt; T & gt; :: delet () {T LastNode = heap [HeapSize--]; Int CurrNode = 1; Int baby = 2; While (hair> lip = heap size) {if (child = heap [hair + 1] .name) { / * If (stack [child] .num == heap [hair + 1] .nom) if (stack [hair] .letter and lt; = heap [hair + 1]. Paper);; * / Child ++; } If (LastNode.num & lt; = heap [child] .num) {/ (If LastNode.num == Hex [Child] .num) {If (Last Node Left> <= Hep [Hair] ;} And * / brake;} heap [currNode] = heap [child]; currNode = child; baby * = 2;} heap [currNode] = last node;} You can only load the comparison operator for and then with the best code As in your commented sections, because it can be confused immediately following and debugging. T
bool operator> (CONST T & amp; left; CONST T & amp; WIGHT) {left left.num> Right.num >> Left.num == right.num & amp; Left.letter & lt; = right.letter;} heap [cornnode / 2] .num . Heap [CurrNode / 2] & gt; E .
Comments
Post a Comment