1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
victus00 [196]
3 years ago
14

Create a generic bubble sort method. Refer to the pseudo code below for a description of the sorting algorithm. Your method must

be able to sort an array of any type of objects that implements the Comparable interface. Create a main method that creates an array of 100 integers. The integers are to be randomly selected, ranging from 0 to 999, inclusive. Also, create an array of 100 doubles. The doubles are to be randomly generated and ranging from 0 to 100. Display the contents of both arrays before sorting and after sorting in ascending order.
for (int k=1;k for (int i=0; i if(list[i] >list[i+1])
swap list[i] with list[i+1];
}
}
Computers and Technology
1 answer:
tangare [24]3 years ago
7 0

Answer:

import java.util.Arrays;

import java.util.Random;

public class GenericSort{

/**

* Method for swapping the value

* @param list

* @param i

* @param j

*/

private static <T> void swap(T[] list, int i, int j) {

if (i != j) {

T temp = list[i];

list[i] = list[j];

list[j] = temp;

}

}

/**

* Generic method for sorting array

* who implement the comparable interface

* @param list

*/

public static <T extends Comparable<T>> void bubble_sort_(T[] list) {

//used the given algo

for (int k=1;k<list.length; k++){

for (int i=0; i<list.length-k;i++){

//using the compareTo method from comparable interface

if(list[i].compareTo(list[k])>0) {

swap(list,k,i);

}

}

}

}

public static void main(String[] args) {

Random rand = new Random();

//Array for int and double

Integer intArray[ ] = new Integer[100];

Double doubleArray []= new Double[100];

for(int i = 0;i<100;i++) {

intArray[i] = rand.nextInt(1000);

doubleArray[i] = 0 + (1000 - 0) * rand.nextDouble();

}

System.out.println("Integer Array Before Sorting ...");

System.out.println(Arrays.toString(intArray));

bubble_sort_(intArray);

System.out.println("Integer Array After sorting.....");

System.out.println(Arrays.toString(intArray));

System.out.println("\n\nDouble array Before Sorting ....");

System.out.println(Arrays.toString(doubleArray));

bubble_sort_(doubleArray);

System.out.println("Double array after sorting ...");

System.out.println(Arrays.toString(doubleArray));

}

}

Explanation:

You might be interested in
An organism which must obtain its food from other organism is called a ​
Sophie [7]

Answer:

Heterotrophs

Explanation:

Heterotrophs, or consumers, are organisms that must obtain energy by consuming other organisms (autotrophs or other heterotrophs) as food.

5 0
4 years ago
Read 2 more answers
How should a common data source, like social media comments, be categorized
Masja [62]

Answer:

unstructured data

Explanation:

Sources that are likely to give you unstructured data might be: Social media posts

4 0
2 years ago
What do mobile platforms utilize to stream voice, IP telephony, mobile internet access, video calling, gaming services, cloud co
Anuta_ua [19.1K]

Answer:

4G/5G.

Explanation:

The broadband cellular network technology that mobile platforms utilize to stream voice, IP telephony, mobile internet access, video calling, gaming services, cloud computing, high-definition mobile TV, and mobile 3-D TV is 4G/5G.

4G technology refers to the fourth generation broadband cellular network technology that is typically used for cellular communications on mobile phones and it is considered to have an internet speed that is ten times faster than what is obtainable on the third generation (3G) broadband technology.

Similarly, 5G is the fifth generation broadband cellular network technology that succeeded 4G and it offers higher quality in terms of performance, reliability, availability and efficiency.

As a result of the speed and high quality specifications of the 4G/5G broadband cellular network technology, they are widely used for various communications systems.

5 0
3 years ago
Dr. Collins has a personal website where he encourages his students to solve questions and discuss topics he taught in class. Wh
joja [24]

Answer:

the answer is c i believe?

Explanation:

4 0
3 years ago
Read 2 more answers
What is Computer system software <br>​
myrzilka [38]

Answer:

<em><u>System</u></em><em><u> </u></em><em><u>soft</u></em><em><u>ware</u></em> is software designed to provide a platform for other software...

6 0
4 years ago
Other questions:
  • The weakest hydrogen line stars are classified as:
    10·2 answers
  • The __________ level focuses on developing the ability and vision to perform complex, multidisciplinary activities and the skill
    9·1 answer
  • Sharon is thinking about opening a bakery. She knows she wants to set her own hours, reduce her stress and make a profit. But sh
    6·2 answers
  • What’s the difference between the logical and physical structure of a file? What are the advantages of not having an application
    15·1 answer
  • What is stored in alpha after the following code executes?
    9·1 answer
  • CIST 1122 Project 2 Instructions
    11·1 answer
  • You are called to assist in troubleshooting a network problem that has occurred soon after a significant IPv6 implementation. So
    11·1 answer
  • The data-mining technique that creates a report or visual representation is _____.
    13·1 answer
  • What do you use to put information into a computer?
    9·2 answers
  • What is the importance of charts and graphics in providing<br> information?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!