Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 16, Problem 2PC
Sorting Objects with the Quicksort
The IntQuickSorter class presented in this chapter sorts an array of int values. Create an ObjectQuickSorter class that can sort Comparable objects. Demonstrate the class in a
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
solve this by c programming
Write a program that deletes the first element in an array which matches a search key. Andprint the new array after deletion.
We can use an array to create a priority queue. Choose from the following options: a. sort the objects by priority b. store data at random and then seek for the highest priority a. neither sorting nor searching b. neither sorting nor searching c. neither sorting nor searching d. neither sorting nor
import java.util.Scanner;import java.util.ArrayList;
public class UserIDSorting {// TODO: Write the partitioning algorithm - pick the middle element as the // pivot, compare the values using two index variables l and h (low and high), // initialized to the left and right sides of the current elements being sorted,// and determine if a swap is necessarypublic static int partition(ArrayList<String> userIDs, int i, int k) {}
// TODO: Write the quicksort algorithm that recursively sorts the low and // high partitionspublic static void quicksort(ArrayList<String> userIDs, int i, int k) {}
public static void main(String[] args) {Scanner scnr = new Scanner(System.in);
ArrayList<String> userIDList = new ArrayList<String>();
String userID;
userID = scnr.next();while (!userID.equals("-1")) {userIDList.add(userID);userID = scnr.next();}// Initial call to quicksort quicksort(userIDList, 0, userIDList.size() - 1);
for (int i = 0; i < userIDList.size(); ++i)…
Chapter 16 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 16.1 - Prob. 16.1CPCh. 16.1 - Prob. 16.2CPCh. 16.1 - Prob. 16.3CPCh. 16.1 - Prob. 16.4CPCh. 16.2 - Prob. 16.5CPCh. 16.2 - Prob. 16.6CPCh. 16.2 - Prob. 16.7CPCh. 16.2 - If a sequential search is performed on an array,...Ch. 16.3 - Prob. 16.9CPCh. 16.3 - Prob. 16.10CP
Ch. 16.3 - Prob. 16.11CPCh. 16.3 - Prob. 16.12CPCh. 16.3 - Prob. 16.13CPCh. 16.3 - Prob. 16.14CPCh. 16.3 - Let a[ ] and b[ ] be two integer arrays of size n....Ch. 16.3 - Prob. 16.16CPCh. 16.3 - Prob. 16.17CPCh. 16.3 - Prob. 16.18CPCh. 16 - Prob. 1MCCh. 16 - Prob. 2MCCh. 16 - Prob. 3MCCh. 16 - Prob. 4MCCh. 16 - Prob. 5MCCh. 16 - Prob. 6MCCh. 16 - Prob. 7MCCh. 16 - Prob. 8MCCh. 16 - Prob. 9MCCh. 16 - Prob. 10MCCh. 16 - True or False: If data is sorted in ascending...Ch. 16 - True or False: If data is sorted in descending...Ch. 16 - Prob. 13TFCh. 16 - Prob. 14TFCh. 16 - Assume this code is using the IntBinarySearcher...Ch. 16 - Prob. 1AWCh. 16 - Prob. 1SACh. 16 - Prob. 2SACh. 16 - Prob. 3SACh. 16 - Prob. 4SACh. 16 - Prob. 5SACh. 16 - Prob. 6SACh. 16 - Prob. 7SACh. 16 - Prob. 8SACh. 16 - Prob. 1PCCh. 16 - Sorting Objects with the Quicksort Algorithm The...Ch. 16 - Prob. 3PCCh. 16 - Charge Account Validation Create a class with a...Ch. 16 - Charge Account Validation Modification Modify the...Ch. 16 - Search Benchmarks Write an application that has an...Ch. 16 - Prob. 8PCCh. 16 - Efficient Computation of Fibonacci Numbers Modify...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What does a comparator do?
Digital Fundamentals (11th Edition)
Write code that opens an output file with the filename number_list. txt, but does not erase the file's contents...
Starting Out with Python (4th Edition)
What output will be produced by the following code?
Java: An Introduction to Problem Solving and Programming (8th Edition)
Which of the following loops would you use to read all of the items from the file associated with myFile? a. Wh...
Starting Out with Programming Logic and Design (4th Edition)
Describe the difference between the seekg and the seekp functions.
Starting Out with C++: Early Objects (9th Edition)
Define a class for complex numbers. A complex number is a number of the form a + b i where, for our purposes, ...
Problem Solving with C++ (9th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Java Shell Sort but make it read the data 12, 34, 54, 2, 3 from a file not an array // Java implementation of ShellSort class ShellSort { /* An utility function to print array of size n*/ static void printArray(int arr[]) { int n = arr.length; for (int i=0; i<n; ++i) System.out.print(arr[i] + " "); System.out.println(); } /* function to sort arr using shellSort */ int sort(int arr[]) { int n = arr.length; // Start with a big gap, then reduce the gap for (int gap = n/2; gap > 0; gap /= 2) { // Do a gapped insertion sort for this gap size. // The first gap elements a[0..gap-1] are already // in gapped order keep adding one more element // until the entire array is gap sorted for (int i = gap; i < n; i += 1) { // add a[i] to the elements that have been gap // sorted save…arrow_forwardPYTHON import randomrandom.seed = 1 class array: def __init__(self, valuelist): self.__atos = valuelist.copy() # this variable is the array that holds the data def additem(self, value): # adds a item to the array def printarray(self): # prints the self.atos def __contains__(self, key): # To test the binary search change the "__linearsearch" to "__binsearch" return self.__linearsearch(key) def __linearsearch(self, key): # Implements the linear search to find an item in the array ####################################################################### # Remove the pass and write code ####################################################################### pass ####################################################################### # End code ####################################################################### def __binsearch(self, key): temp = sorted(self.atos)…arrow_forwardJava Quick Sort but make it read the data 10, 7, 8, 9, 1, 5 from a file not an array // Java implementation of QuickSort import java.io.*; class GFG { // A utility function to swap two elements static void swap(int[] arr, int i, int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } /* This function takes last element as pivot, places the pivot element at its correct position in sorted array, and places all smaller (smaller than pivot) to left of pivot and all greater elements to right of pivot */ static int partition(int[] arr, int low, int high) { // pivot int pivot = arr[high]; // Index of smaller element and // indicates the right position // of pivot found so far int i = (low - 1); for (int j = low; j <= high - 1; j++) { // If current element is smaller // than the pivot if…arrow_forward
- Problem (class MergeSalary)First, write a Java method merge that takes as parameter a non-empty double array representingemployees’ salaries. The method merges the values of every 2 adjacent elements. put themerged values at the beginning of the array, and put 0 in the remaining positions. Suppose thatthe original array will contain an even number of elements.Second, write two java methods readArray(int[]a) and printArray(int[]a) thatreads/writes the elements of an array passed in parameter from/to the standard input/output.Finally, Use the following main method to test your different methods:public class MergeSalary{ private static Scanner input = new Scanner(System.in); public static void main(String[] args) { double[] salaries = new double[10]; System.out.print("Enter 10 salaries: "); readArray(salaries); merge(salaries); System.out.print("Salaries after merge: "); printArray(salaries); }}arrow_forwardSearches – Directed Lab Work1. When an object does not occur in an array, a sequential search for it must examine the entirearray. If the array is sorted, you can improve the search by using the approach described inExercise 2. A jump search is an attempt to reduce the number of comparisons even further.Instead of examining the n objects in the array a sequentially, you look at the elements a[j],a[2j], a[3j], and so on, for some positive j < n. If the target t is less than one of these objects,you need to search only the portion of the array between the current object and the previousobject. For example, if t is less than a[3j] but is greater than a[2j], you search the elementsa[2j + 1], a[2j + 2], . . ., a[3j - 1] by using the method in Exercise 2 on the textbook’s page544. The implementation should take care of the case when t > a[k × j], but (k + 1) × j > n.Devise an algorithm for performing a jump search.Then, using⌈√n⌉as the value of j, implement the jump search. Add more…arrow_forwardImplement quicksort in a JAVA programming language. The first version will use the first element of the array as the pivot. Please help me with a Java code , It needs to take the input from a file of 100 data elements. Can someone please help me with this coding problem. I have the data set file , but I cannot upload it in here. Kindly help me with the code.arrow_forward
- Consider the 2D array “list”. Each row represent a class say Bangla or English or Math, andthe columns indicates student. A ‘1’ in list[c][s] indicates student s is in class c; a ‘0’ meansstudent s is not in class c. Write a program to display the class number (0/1/2) with the mostnumber of students.arrow_forwardUsing java in netbeans Create a two-dimensional array of type double to contain the three different SD Marks (JD521, PRG521, and IP521) for six different students. A single array of type String must be used to store the student names (Maxwell, Carl, Gerhard, Paul, James, and Cena). Allow a user to enter in a number, ranging from 1 to 6, which will represent the student position in the table MCSD max and present the marks for each respecting module. The program can only stop when the user enter a number greater than 6. Printout the student name including the JD521, PRG521, and IP521 max, the total of marks and the average of all marks. Use a condition statement to decide that the student has passed or not (Pass rate is 70). Student name JD521 PRG521 IPG521 Maxwell 80 65 70 Carl 95 70 65 Gerhard 87 80 73 Paul 65 45 60 James 45 87 65arrow_forwardQ2. Write a java program to perform the following task: a) Create a collection ArrayList<String> for Customer class b) Add 5 elements into ArrayList c) Display the element at index 4 d) Display all the elements in the ArrayList using for-each loop e) Remove the values at index 2 f) Add “cst2” in location 2. g) Check if st2 existing inside the collection.arrow_forward
- java The search method accepts ArrayList of Strings and String find. The method returns a String. It will look for an element within ArrayList that contains value of find if it finds it, methods needs to return whole Element value. if an instance of find doesn't exist return:"search failed" Example: search(["one apple","two orange","four banana"],"four") returns: "four banana" ("four banana" contains "four" so method returns "four banana")arrow_forward8.12 LAB: Binary search Binary search can be implemented as a recursive algorithm. Each call makes a recursive call on one-half of the list the call received as an argument. Complete the recursive method binarySearch() with the following specifications: Parameters: a target integer an ArrayList of integers lower and upper bounds within which the recursive call will search Return value: the index within the ArrayList where the target is located -1 if target is not found The template provides main() and a helper function that reads an ArrayList from input. The algorithm begins by choosing an index midway between the lower and upper bounds. If target == integers.get(index) return index If lower == upper, return -1 to indicate not found Otherwise call the function recursively on half the ArrayList parameter: If integers.get(index) < target, search the ArrayList from index + 1 to upper If integers.get(index) > target, search the ArrayList from lower to index - 1…arrow_forwardJAVA Create a class Book with the following attributesBooKname, BookPublisher, BookYearofPublished5.1 Now create the collection of book objects using treeset and do the followingoperations• Sort by bookname• Reverse sort by bookyearofpublished5.2 Now create the collection of book objects using LinkedHashSet and do thefollowing operation• sort by bookpublisherarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
9.1: What is an Array? - Processing Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=NptnmWvkbTw;License: Standard Youtube License