Add a method bubbleSort to the class ArraySorter, as given in Listing 7.10, that performs a bubble sort of an array. The bubble sort
Bubble sort algorithm to sort an array a
Repeat the following until the array a is sorted:
for (index = 0; index <a. length - 1; index++)
if (a[index] > a [index + 1])
Interchange the values of a [index] and a [index + 1].
The bubble sort algorithm usually requires more time than other sorting methods.
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Java How To Program (Early Objects)
Starting Out With Visual Basic (8th Edition)
Problem Solving with C++ (9th Edition)
Absolute Java (6th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Software Engineering (10th Edition)
- Java - Sort an Arrayarrow_forwardDefine a class Car as follows:class Car { public String make; public String model; public int mpg;// Miles per gallon}a) Implement a comparator called CompareCarsByMakeThenModel that can be passed as an argument to the quicksort method from the lecture notes. CompareCarsByMakeThenModel should return a value that will cause quicksort to sort an array of cars in ascending order (from smallest to largest) by make and, when two cars have the same make, in ascending order by model.b) Implement a comparator called CompareCarsByDescendingMPG that can be passed as an argument to the quicksort method from the lecture notes. CompareCarsByDescendingMPG should return a value that will cause quicksort to sort an array of cars in descending order (from largest to smallest) by mpg.c) Implement a comparator called CompareCarsByMakeThenDescendingMPG that can be passed as an argument to the quicksort method from the lecture notes.…arrow_forwardJavaarrow_forward
- java code that completes tasks forr an array integers. Swaped the first and last elements in array. Replace all even elements with 0. Shift all elements by one to the right and move the last element into the first position. For example, 1 4 9 16 25 would be turned i into 25 1 4 9 16. Replace each element except first and last the larger of its two neighbors.arrow_forwardIn JAVAarrow_forwardwrite a code in java (using recursion)arrow_forward
- Write a Java class to perform the following: 1. Write a method to search the following array using a linear search, ( target elements: 11, 55, 17.). (count the number of comparisons needed). {06, 02, 04, 07, 11, 09, 50, 62, 43, 32, 13, 75, 01, 46, 88, 17} 2. Write a method to sort the array using Selection Sort. (count the number of comparisons needed) 3, Write a method to sort the array using Bubble Sort. (count the number of comparisons needed) 4, Search he sorted array using a binary search (recursive) for the same set of target elements. (count the number of comparisons needed)arrow_forwardJAVAarrow_forward7arrow_forward
- Java Complete the method with explaining, thank you!arrow_forwardJAVAWrite a program that searches person's name and display all matched name. For example, if a user inputs the letter "Davis", the program searches all name which includes "Davis" in an array. Then, display all matched names on the screen. You must declare a single dimensional array which has all people’s name. Use methods of string classarrow_forwardGrey lines of code (Beging - 9 & 13-End of code) can NOT be edited. New Java code myst go inbetween.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education