c - What kind of parameter should I be passing to my merge function in Bottom Up Merge Sort? -
c - What kind of parameter should I be passing to my merge function in Bottom Up Merge Sort? -
i have c code question , bit confused how set parameters in it.
q) using c code finish mergesort function shown below, function must implemented iteratively. can assume existence of merge function next header , phone call it(you not have write merge function).
so far given this:
void merge(int arr[], int start, int mid, int end); void mergesort(int arr[], int len) { // write code here }
here progress did research , found out iterative way of doing merge sort called bottom merge sort.:
void mergesort(int arr[], int len) { int windows; (windows = 1; windows < len; windows = 2* windows) { int i; (i = 0; < len; i+ 2*windows) { // not sure pass remaining parameters. merge(arr, i, ??, ??)); } } }
what have envisioned combine adjacent elements each time 1, 2, 4, 8, 16 ect ect(according youtube) merge function "assume" exists. can explain me should passing merge function remaining parameters? assuming have written merge function successively combines adjacent elements (windows).i know requires sort of logical math, weak in math , coincidentally taking calculus right well..
assuming passing array has size of powerfulness of 2 should work:
void mergesort(int arr[], int len) { int windows; (windows = 1; windows < len; windows = 2* windows) { int i; (i = 0; < len; i+ 2*windows) { // not sure pass remaining parameters. merge(arr, i, i+windows, i+2*windows)); } } }
c mergesort
Comments
Post a Comment