C++

Rama A.

asked • 03/23/21

how can I rewrite this code

  1. void insertion_with_jumps(string a[], int n, int jump):
  2. Performs insertion sort on the given array using the given jump. This does not necessarily sort the array (unless the jump is 1) and is only one step in Jumping Sort.
  3. void jumping_sort(string a[], int n):
  4. Sorts the array by calling function insertion_with_jumps using the following sequence of jumps: 2n​,4n​,8n​,…,1.

#THE CODE#

void insertion_with_jumps(string a[], int n, int jump) {

for(int i=jump;i<n;i++){

string arr=a[i];

int j;

for(j=i-jump;j>=0 && arr<a[j];j=j-jump){

a[j+jump] = a[j];}

a[j+jump]=arr;}

}


void jumping_sort(string a[], int n) {

for(int jump=n/2; jump>0; jump=jump/2){

insertion_with_jumps(a, n, jump);

}


}



1 Expert Answer

By:

Patrick B. answered • 03/23/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Rama A.

Thank you !
Report

03/24/21

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.