
Concept explainers
Design and implement a Java program/application that
1. Uses at least one of the following collections:
a. Stack
b. Queue
c. List
d. Tree
2. Uses at least one of the following searching methods:
a. Linear search
b. Binary search
3. Uses at least one of the following sorting methods:
a. Bubble sort
b. Insertion sort
c. Selection sort
d. Quick sort
e. Merge sort
I'm using an insertion sort for this project. I would like help implementing a list collection type and binary search method.
//Project with Insertion sort
import java.util.Random;
public class main{
static void insertionSort(int arr[]){
int n = arr.length;
for (int i = 1; i < n; ++i){
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key){
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
public static void main(String[] args){
int max = 100;
int min = 1;
int arr[]=new int[10];
Random randomNum = new Random();
for(int i=0;i<arr.length;i++){
arr[i] = min + randomNum.nextInt(max);
}
System.out.println("Array of random number is: ");
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+ " ");
}
insertionSort(arr);
System.out.println("\nSorted array is: ");
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+ " ");
}
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images

I'd like to know the
import java.util.Random;
import java.util.*;
public class main{
static void insertionSort(int arr[]){
int n = arr.length;
for (int i = 1; i < n; ++i){
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key){
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
public static void main(String[] args){
int max = 100;
int min = 1;
int arr[]=new int[10];
int n;
@SuppressWarnings("resource")
Scanner sc=new Scanner(System.in);
Random randomNum = new Random();
for(int i=0;i<arr.length;i++){
arr[i] = min + randomNum.nextInt(max);
}
System.out.println("Array of random number is: ");
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+ " ");
}
insertionSort(arr);
System.out.println("\nSorted array is: ");
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+ " ");
}
System.out.println();
System.out.print("\nEnter an element to search: ");
n=sc.nextInt();
List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < arr.length; i++){
list.add(arr[i]);
}
System.out.println("The element is at position: "+(Collections.binarySearch(list, n)+1));
}
}
I'd like to know the
import java.util.Random;
import java.util.*;
public class main{
static void insertionSort(int arr[]){
int n = arr.length;
for (int i = 1; i < n; ++i){
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key){
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
public static void main(String[] args){
int max = 100;
int min = 1;
int arr[]=new int[10];
int n;
@SuppressWarnings("resource")
Scanner sc=new Scanner(System.in);
Random randomNum = new Random();
for(int i=0;i<arr.length;i++){
arr[i] = min + randomNum.nextInt(max);
}
System.out.println("Array of random number is: ");
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+ " ");
}
insertionSort(arr);
System.out.println("\nSorted array is: ");
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+ " ");
}
System.out.println();
System.out.print("\nEnter an element to search: ");
n=sc.nextInt();
List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < arr.length; i++){
list.add(arr[i]);
}
System.out.println("The element is at position: "+(Collections.binarySearch(list, n)+1));
}
}
- Parallel Lists JumpinJive.py >- Terminal Summary 1 # JumpinJava.py - This program looks up and prints t and prices of coffee orders. 2 # Input: In this lab, you use what you have learned about parallel lists to complete a partially completed Interactive Python program. 3 # Output: Name and price of coffee orders or error if add-in is not found 4 The program should either print the name and price for a coffee add-in from the Jumpin' Jive 5 # Declare variables. Coffee Shop or it should print the message "Sorry, we do not carry that.". 6 NUM_ITEMS = 5 # Named constant 8 # Initialized list of add-ins 9 addIns = ["Cream", "Cinnamon", "Chocolate", "Amarett "Whiskey"] Read the problem description carefully before you begin. The data file provided for this lab includes the necessary input statements. You need to write the part of the program that searches for the name of the coffee add-in(s) and either prints the name and price of the add-in or prints 10 the error message if the add-in is not…arrow_forwardPut the following code in a main.py file and a module.py file. Define the names sort, list_max and sum_of_list after putting the code into a main file and a module file #predefined modules import random import math #function to sort the list in ascending order def sort(x): #predefined function sort() x.sort() #print the sorted list print("\nSorted list is: ",str(x)) #function to find the sum of list elements def sum_of_list(x): #predefined function sum() Sum=sum(x) #return the sum of list elements return Sum #function to list the maximum from the list def list_max(x): #predefined function max() maximum=max(x) #return maximum return maximum #function to test the above three function def main(): #set a flag variable flag=True #create a list list1=list() #initialize the list element by using randrange() predefined function of random module list1=[random.randrange(1, 50, 1) for i in range(0,7)] #print the…arrow_forwardWrite a python program that takes two lists, merges thetwo lists, sorts the resulting list, and then finds the median of theelements in the two lists. You cannot use python build-in sort() function #todo#You can use math functions like math.floor to help the calculationimport math #todo#You can use math functions like math.floor to help the calculation import math def task7(list_in_1, list_in_2): # YOUR CODE HERE return median please use these variables no print function pleasearrow_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





