Home > Blockchain >  Function must return a value error even when it does
Function must return a value error even when it does

Time:05-09

This is my code for counting inversions using merge sort but I'm getting the error "merge_sort : function must return a value" but as you can see the function does return a value. How do I fix this?

int merge_sort(std::vector<int>& src, int begin, int end)
{
    if (begin >= end) return;

    int mid = (begin   end) / 2;

    int leftinv = merge_sort(src, begin, mid);
    int rightinv = merge_sort(src, mid   1, end);
    int splitinv = merge(src, begin, mid, end);

    return leftinv   rightinv   splitinv;
}

CodePudding user response:

Could it be the conditional return: "if (begin >= end) return;"

  • Related