Add a method insertionSort to the class ArraySorter, as given in Listing 7.10, mat performs an insertion sort of an array. To simplify this protect, our insertion sort
Inserting into a sorted array
Insertion sort algorithm to sort an array
for (index = 0; index <a.length; index++)
Insert the value of a [index] into its correct position in the array temp, so that all the elements copied into the array temp so far are sorted.
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
Software Engineering (10th Edition)
Starting Out with C++: Early Objects (9th Edition)
Using MIS (10th Edition)
Database Concepts (7th Edition)
Database Concepts (8th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- in c++arrow_forward3. Remove an element from an array Consider an array named source. Write a method/function named remove( source, size, idx) that removes the element in index idx of the source array. You must execute the method by passing an array, its size and the idx( that is the index of the element to be removed). After calling the method, print the array to show whether the element of that particular index has been removed properly. Example: source=[10,20,30,40,50,0,0] remove(source,5,2) After calling remove(source,5,2) , printing the array should give the output as: [ 10,20,40,50,0,0,0] [Use Python and Don't use Built-in function like "pop"]arrow_forward3. Remove an element from an array Consider an array named source. Write a method/function named remove( source, size, idx) that removes the element in index idx of the source array. You must execute the method by passing an array, its size and the idx( that is the index of the element to be removed). After calling the method, print the array to show whether the element of that particular index has been removed properly. Example: source=[10,20,30,40,50,0,0] remove(source,5,2) After calling remove(source,5,2) , printing the array should give the output as: [ 10,20,40,50,0,0,0] Use Python languagearrow_forward
- Write in java code Create an array myArr of 10 integer elements and initialize/fill it with numbers (not sorted) between 0 and 20; for example myArr = [ 12, 3, 19, 5, 7, 11,….etc.]. (a) print the array. (b) Use method sort() of class Arrays to sort myArr and print it after sorting. (c) Use the arraycopy() method of class System to copy myArr to another array called my2ndArr, then print both arrays. (d) use method equals() of class Arrays between the two arrays and print the results. (e) use method fill() to fill my2ndArr with 99 in all elements and then use method equals()and print the result whether the two arrays are equal or not. (f) use the method binarySearch() to search myArr for the value 15 and print the resultarrow_forwardWrite a Java program tat prompts user for a list of integers with 0 as the last value.Save the values in an array. Assume there can be maximum 100 values. Theprogram should have the following methods:- A method that takes the array as parameter and updates each value in thearray to the square of the value.- Another method that takes the original and modified arrays as parametersand displays the original and the squared values.arrow_forwardPlz answer in java onlyarrow_forward
- Write the full Java Code for LabProgram.javaarrow_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_forwardjava 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_forward
- Solve it quick in javaarrow_forwardIntellij - Java Write a program which does the following: Create a class with the main() method. Take a string array input from the user in main() method. Note: Do not hardcode the string array in code. After the String array input loop, the array should be: words[] = {"today", "is", "a", "lovely", "spring","day", "not", "too", "hot", "not", "too", "cold"}; Print the contents of this array using Arrays.toString() method. Write a method called handleString() that performs the following: Takes a String[] array as method parameter (similar to main method). Loop through the array passed as parameter, and for each word in the array: If the length of the word is even, get the index of the last letter & print that index. Use length() and indexOf() String object methods. If the string length is odd, get the character at the 1st position in the string & print that letter. Use length() and charAt() String object methods.arrow_forwardYour Friendly Array Neighbor Program only in java not in python Create a Java program that takes an array called ar as an input that keeps track of arrays. Every day a new array is produced using the array of the previous day. On the n’th day, the following operations are performed on the array of day n – 1 to produce the array of day n: -If an element is smaller than both left and right neighbor, then this element is incremented -If an element is bigger than both its left neighbor and its right neighbor, then this element is decremented. -The first and last elements should never change Eventually after some days the array will not change, some examples: Example: Input from user: ar = [6,2,3,4] Output from program: [6,3,3,4] After the first day the array is changed from [6,2,3,4] to [6,3,3,4] and no further operations may be completed. Example: Input from user: ar = [1,6,3,4,3,5] Output from program: [1,4,4,4,4,5] After the first day the array is changed from [1,6,3,4,3,5]…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning