1
def seq_merge_sort(arr):
    rght = 0; wid = 0; rend = 0; left = 0
    k = 1

    num = len(arr)
    temp = [0] * num

    while(k < num):
        while(left + k < num):
            rght = left + k
            rend = rght + k
            if(rend > num):
                rend = num
            m = left; i = left; j = rght

            while(i < rght and j < rend):
                if (arr[i] <= arr[j]):
                    temp[m] = arr[i]
                    i += 1
                else:
                    temp[m] = arr[j]
                    j += 1
                m += 1

            while(i < rght):
                temp[m] = arr[i]
                i += 1; m += 1
            while(j < rend):
                temp[m] = arr[j]
                j += 1; m += 1
            m = left
            while(m < rend):
                arr[m] = temp[m]
                m += 1
            left += k * 2
        k *= 2
    return arr

I made this code in python with similar code in C#, but it worked only halfway through. For example, some parts are sorted, but some parts are same as input.

I tried to fix it, but it really make me hard. It will be thanks to great coder who make this sorting perfect!

Chris
  • 1,206
  • 2
  • 15
  • 35
J HoYA
  • 41
  • 5
  • When asking for help with homework, ask for little pieces. People don't want to do your assignment for you. A small chunk of code that isn't doing what you expect, or a stack trace are much more likely to get help. On topic- name your variables so that people's eyes don't bleed trying to follow and pull pieces of code out into functions just to lessen the cognitive load. Does it _have_ to be non-recursive? Merge sort is easier to reason about recursively... I may even suggest getting that working first and then translating it. – Paul Becotte Nov 15 '19 at 04:37

0 Answers0