How do I call Recursive Function ?

  • Hi, guys

    I try to convert a C++ code to C2 code, It is a Recursive Function.

    code here

    void mergeSort(int array[], int first, int last) {
        if(first < last) {
            int middle = int((first + last) / 2);
            mergeSort(array, first, middle);
            mergeSort(array, middle + 1, last);
            merge(array, first, middle, last);
        }
    }[/code:43xwtj4z]
    
    I try to
    [img="https://drive.google.com/uc?export=download&id=0B8g2b8f9ktNBVVpubG01OVJ4Yk0"]
    
    but I receive a bug "Maximum call stack size exceeded".
    
    Its seem I can't call 2 times mergeSort Function. Someone can help me!
    
    Please Excuse my poor English
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • There's not enough here to work with. Your array is blank, you are arbitrarily sending 0 and 7 as parameters, and the "merge" function isn't there. You've hard coded the "last" as 7 on the second call. If you follow the source exactly, it should work. Start by having locals for first and last, set them from the Params, then it will be easier to follow. You are taking too many shortcuts.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)