Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose I need to write a bubble sort with a test program, shell sort function w

ID: 3875738 • Letter: S

Question

Suppose I need to write a bubble sort with a test program, shell sort function with a test program and a quick sort function (using stacks preferred) with a test program, then a main program that includes previous three programs. In the test programs, I need to print the random numbers, sort the numbers keeping track of the cost, print the sorted numbers and the cost. I also have to use __INCLUDE_LEVEL_ in all of the programs, which includes the sorting routines and a test program. The main program should have: 1)Generate 20 random numbers. Print the random numbers

2)Move the original random numbers into another array. Bubble sort the other array. Print the sorted numbers and the cost of sorting the numbers.

3) Move the original random numbers into another array. Shell sort the other array. Print the sorted numbers and the cost of sorting the numbers.

4) Move the original random numbers into another array. Quick sort the other array. Print the sorted numbers and the cost of sorting the numbers.

To compute the cost, I need to assign values to every swap and every compare. A compare costs 1 unit, and a swap costs 6 unit.

This is what I have so far:

bubbleSort.cpp:

quickSort.cpp:

shellSort.cpp:

mian.cpp:

And when I compile, my result is this (first pircture), when it has to look like the second picture. I think it's because I don't have main functions in 3 programs (bubble sort, quick sort and shell sort) if I'm correct ? Can anybody fix them so my result looks like the second picture?? (in c++) Please include __INCLUDE_LEVEL_ as stated above!

Thank you!

Cost of Bubble Sort: 763 Cost of Bubble Sort: 763 Cost of Bubble Sort: 763 Cost of Bubble Sort: 763 Cost of Bubble Sort: 763 Cost of Bubble Sort: 763 1 Cost of Bubble Sort 763 1 Cost of Bubble Sort: 763 84 Cost of Bubble Sort: 763 32561 Cost of Bubble Sort: 763 32561. Cost of Bubble Sort: 763 32766 Cost of Bubble Sort: 763 65535 Cost of Bubble Sort: 763 4196272 Cost of Bubble Sort 763 4198419 Cost of Bubble Sort 763 6299128 Cost of Bubble Sort: 763 6299760 Cost of Bubble Sort: 763 195920376 Cost of Bubble Sort: 763 196101161 Cost of Bubble Sort: 763 1604233280 Cost of Bubble Sort: 763

Explanation / Answer

THE BELOW CODE WHICH IS EXECUTED BEFORE AND WORKED ACCORDINGLY. IT MAY HELP YOU.

IF ANY QUERIES GET BACK TO ME

CODE

import java.util.Random;
public class Sort
{
public static void bubbleSort(int array[])
{
int cost = 0;
int n = array.length;
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if (array[j] > array[j+1])
{
int temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
cost = cost + 7;
}
printarray(array);
System.out.println("Cost of the sorting is : " + cost);
}
  
public static void shellSort(int array[])
{
int cost = 0;
int n = array.length;
for (int g = n/2; g > 0; g /= 2)
{
for (int i = g; i < n; i += 1)
{
int temp = array[i];
int j;
for (j = i; j >= g && array[j - g] > temp; j -= g)
{
array[j] = array[j - g];
cost = cost + 7;
}
array[j] = temp;
}
}
printarray(array);
System.out.println("Cost of the sorting is : " + cost);
}

public static int part(int array[], int l, int h)
{
int p = array[h];
int i = (l-1);
for (int j=l; j<h; j++)
{
if (array[j] <= p)
{
i++;
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
int temp = array[i+1];
array[i+1] = array[h];
array[h] = temp;

return i+1;
}

public static void quickSort(int array[], int l, int h)
{
if (l < h)
{
int pi = part(array, l, h);
quickSort(array, l, pi-1);
quickSort(array, pi+1, h);
}
printarray(array);
}

public static void printarray(int array[])
{
int n = array.length;
for (int i=0; i<n; ++i)
System.out.print(array[i] + " ");
System.out.println();
}
  
public static void main(String []args)
{
int[] inputs = new int[20];
int[] b_temp = new int[20];
int[] s_temp = new int[20];
int[] q_temp = new int[20];
Random rand = new Random();
for (int i=0; i<20;i++)
{
int temp = rand.nextInt(100) + 1;
inputs[i] = temp;
b_temp[i] = temp;
s_temp[i] = temp;
q_temp[i] = temp;
}
bubbleSort(b_temp);
shellSort(s_temp);
quickSort(q_temp, q_temp[0], q_temp[19]);
}
}

THANK YOU

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote