Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Based on the code bellow, could someone please make a Javadoc that will describe each field and method of a class, its diffrent from pseudo

Based on the code bellow, could someone please make a Javadoc that will describe each field and method of a class, its diffrent from pseudo code, it should be a list that code be written into a word document, not comments in the code.

bellow is the code, Thank you!

import java.util.Random;

public class TestClass { public static void main(String[] args) { int bubbleValues[] = new int[20]; int selectionValues[] = new int[20]; int insertionValues[] = new int[20]; int quickValues[] = new int[20]; Random input = new Random(); for(int i = 0; i < 20; i++){ bubbleValues[i] = input.nextInt(100); selectionValues[i] = input.nextInt(100); insertionValues[i] = input.nextInt(100); quickValues[i] = input.nextInt(100); } SortingBenchMarks in = new SortingBenchMarks(); int bubbleCount = in.bubbleSort(bubbleValues); int selectionCount = in.selectionSort(selectionValues); int insertionCount = in.insertionSort(insertionValues); int quickCount = in.quickSort(quickValues); System.out.println("Elements in the bubble array: "); for(int i =0; i < 20; i++){ System.out.print(" " +bubbleValues[i]); } System.out.println(); System.out.println("Elements in the selection array:"); for(int i = 0; i <20; i++){ System.out.print( " " +selectionValues[i]); } System.out.println(); System.out.println("Elements in the insertion array:"); for(int i = 0; i <20; i++){ System.out.print( " " +insertionValues[i]); } System.out.println(); System.out.println("Elements in the quick array:"); for(int i = 0; i <20; i++){ System.out.print( " " +quickValues[i]); } System.out.println(); System.out.println("Bubble swaps: " +bubbleCount); System.out.println("Selection swaps: " +selectionCount); System.out.println("Insertion swaps: " +insertionCount); System.out.println("Quick swaps: " +quickCount); }

}

=============================================================================================

public class SortingBenchMarks { int bubbleCount = 0; int selectionCount = 0; int insertionCount = 0; int quickCount = 0; public int bubbleSort(int[] array) { int maxElement; int index; int temp; for(maxElement = array.length - 1; maxElement >=0; maxElement--){ for(index = 0; index <= maxElement - 1; index++){ if(array[index] > array[index + 1]){ temp = array[index]; array[index] = array[index + 1]; array[index + 1] = temp; bubbleCount += 2; } } } return bubbleCount; } public int selectionSort(int[] array) { int strtScan; int indx; int minIndx; int miniValue; for(strtScan = 0; strtScan < (array.length-1); strtScan++){ minIndx = strtScan; miniValue = array[strtScan]; for(indx = strtScan + 1; indx < array.length; indx++){ if(array[indx] < miniValue){ miniValue = array[indx]; minIndx = indx; } } array[minIndx] = array[strtScan]; array[strtScan] = miniValue; selectionCount += 2; } return selectionCount; } public int insertionSort(int[] array){ int unsortedValue; int scan; for(int index = 1; index < array.length; index++){ unsortedValue = array[index]; scan = index; while(scan > 0 && array[scan - 1] > unsortedValue){ array[scan] = array[scan - 1]; scan--; insertionCount++; } array[scan] = unsortedValue; insertionCount++; } return insertionCount; } public int quickSort(int array[]){ doQuickSort(array, 0, array.length - 1); return quickCount; } private void doQuickSort(int array[], int start, int end){ int pivotPoint; if(start < end){ pivotPoint = partition(array, start, end); doQuickSort(array, start, pivotPoint - 1); doQuickSort(array, pivotPoint + 1, end); } } private int partition(int array[], int start, int end){ int pivotValue; int endOfLeftList; int mid; mid = (start + end) / 2; swap(array, start, mid); pivotValue = array[start]; endOfLeftList = start; for(int scan = start + 1; scan <= end; scan++){ if(array[scan] < pivotValue){ endOfLeftList++; swap(array, endOfLeftList, scan); } } swap(array, start, endOfLeftList); return endOfLeftList; } private void swap(int[] array, int a, int b){ int temp; temp = array[a]; array[a] = array[b]; array[b] = temp; quickCount += 2; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions