Stack Over Flow RRS feed

  • Question

  • Sub MakeMaxHeap(i, heapsize)

    Dim LeftChild As Long
    Dim RightChild As Long
    Dim Largest As Long

    Largest = i

    LeftChild = 2 * i
    RightChild = 2 * i + 1

        If LeftChild <= heapsize Then
            If A(i, 1) = A(LeftChild, 1) Then
                Largest = RightChild
            End If
        End If

        If RightChild <= heapsize Then
            If A(Largest, 1) = A(RightChild, 1) Then
                Largest = LeftChild
            End If
        End If
    M = A(i, 1)
    A(i, 1) = A(Largest, 1)
    A(Largest, 1) = M
        If Largest <> 1 Then
        Call MakeMaxHeap(Largest, heapsize)
        End If

    End Sub

    When I run my HeapSort code, I keep getting a "Stack Over Flow Error" that directly links to my code above.

    after running it, it highlights what is in  bold above when debugging.

    Sunday, March 5, 2017 2:15 PM

All replies

  • Your error is typical for recursion. You've not enough memory or you don't stop at the right moment and then the stack goes above what is available. 

    With your given code is almost impossible to tell how to solve that, also without any debugging it is mostly impossible to find where the problem is. 

    Normally is that it never stops when this error is given.


    Sunday, March 5, 2017 2:19 PM
  • If your program should implement the ‘Max-Heapify’ pseudocode (, then note that it uses ‘>’ instead of ‘=’ in several places. There are some other differences too.

    Sunday, March 5, 2017 8:09 PM