Question

Create an Eclipse Java project that utilize "Bubble Sort" to sort an unsorted integer array of...

Create an Eclipse Java project that utilize "Bubble Sort" to sort an unsorted integer array of size 10. The main method should display unsorted array and sorted array after Bubble Sort. NEED A WORKING JAVA PROJECT. NEED IT ASAP

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class BubbleSortInt {

  //Bubble sort function
  public static void bubbleSort(int[] array) {
    for (int i = 0; i < array.length - 1; i++)
      for (int j = 0;j<array.length-i-1;j++)
        if (array[j] > (array[j + 1])) {
          int temp = array[j];
          array[j] = array[j + 1];
          array[j + 1] = temp;
        }
  }

  public static int[] readInput(){
    Scanner scanner = new Scanner(System.in);

    //Reading size of array
    int n = 10;
    //Reading n number of values to array
    System.out.println("Enter "+n+" values");
    int arr[] = new int[n];
    for(int i = 0;i<n;i++){
      arr[i] = scanner.nextInt();
    }
    return arr;
  }

  public static void main(String args[]) {
    int sub[] = readInput();

    // Printing unsorted array
    System.out.println("\nUnsorted array:");
    for(int i = 0;i<sub.length;i++)
      System.out.print(sub[i]+" ");
    System.out.println("\n");

    //Calling bubble sort
    bubbleSort(sub);

    //Printing the sorted array after calling bubbleSort function
    System.out.println("Sorted array:");
    for(int i = 0;i<sub.length;i++)
      System.out.print(sub[i]+" ");
    System.out.println();
  }
}

Add a comment
Know the answer?
Add Answer to:
Create an Eclipse Java project that utilize "Bubble Sort" to sort an unsorted integer array of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in java Create an Eclipse Java project that utilize "Selection Sort" to sort an unsorted integer...

    in java Create an Eclipse Java project that utilize "Selection Sort" to sort an unsorted integer array of size 20 of random numbers in the range 0-500 inclusive. The main method should display the unsorted array and sorted array after Selection Sort.

  • Write a Java program with a single-dimension array that holds 11 integer numbers and sort the...

    Write a Java program with a single-dimension array that holds 11 integer numbers and sort the array using a bubble sort. Next, identify the median value of the 11 integers. Here are the steps your program must accomplish. algorithm (either flowchart or pseudocode) that you will use to write the program Step 1. Create an Place the algorithm in a Word document. 6. Ste the Step 2. Code the program in Eclipse and ensure the following steps are accomplished. 1....

  • In Java Create an array of Student objects. Display the students by age in UNSORTED order....

    In Java Create an array of Student objects. Display the students by age in UNSORTED order. Apply the Quick sort and Display the students by age in SORTED order. public class TestQuickStudent { public static void main (String [ ] args ) { /* ***Create your array of Student objects with AT LEAST 5 names */ System.out.println ( " ____________________________");    /* ***LOOP through your array and print out each UNSORTED check by student age */ System.out.println ( " ____________________________");...

  • JAVA PLEASE Using queues Radix sort Come up with an unsorted array of numbers (integer array)....

    JAVA PLEASE Using queues Radix sort Come up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order.

  • Write a JAVA Program: Compare the performance of bubble sort and selection sort over several arrays....

    Write a JAVA Program: Compare the performance of bubble sort and selection sort over several arrays. - Write two methods that sort arrays of doubles. One method should use selection sort, and the other should use bubble sort. - In each of the sort methods, add code that counts the total number of comparisons and total number of swaps performed while sorting the entire array (be careful; don't count each pass through the array separately) - Each time an array...

  • Qi. Create a java project Question that includes: • A bubble sort method to sort your...

    Qi. Create a java project Question that includes: • A bubble sort method to sort your arrays. Implement the below recursive binary search. • A java main class where you: o Create an array of characters that contains the letters of your first name followed by your last name, without spaces. o Call the sorting method to sort the array o Call binary search method to find the position of the first letter 'a' in your array. // Recursive Binary...

  • Analyze two sorts in C++, the first being a bubble sort and the second being a...

    Analyze two sorts in C++, the first being a bubble sort and the second being a quick sort. Create a project for each sort. Use 4 data set sizes. Results will be based on execution time for each sort. The size should have a regular increment. For example, using a regular increment of 10,000, you might have sizes of 10,000, 20,000, 30,000, and 40,000. Choose your data size based upon the ability to obtain meaning results. Need: Two screen shots...

  • need help!! java eclipse Write a program to implement bubble sort, insertion sort, selection sort, merge...

    need help!! java eclipse Write a program to implement bubble sort, insertion sort, selection sort, merge sort and quick sort (pivot - first index) algorithms. a) Compute the CPU processing time for all the algorithms for varying input sizes as follows: N-10, 103, 10, 10, and 106 b) Use a random number generator to generate the inputs. Obtain the inputs from the following input ranges: 1- 10, 1 -10, 1 - 10, 1 12 10 c) Write down your results...

  • TO DO: IMPLEMENT SELECTION SORT, BUBBLE SORT, MERGE SORT INSTRUCTIONS: GENERATE AN ARRAY arr AND FILL...

    TO DO: IMPLEMENT SELECTION SORT, BUBBLE SORT, MERGE SORT INSTRUCTIONS: GENERATE AN ARRAY arr AND FILL IT WITH 100 RANDOM INTEGERS, HAVING VALUES 0-99. PRINT THE UNSORTED ARRAY IMPLEMENT EACH SORTING ALGORITHM (DO NOT USE THE BUILT-IN LIBRARIES) FOR EACH ALGORITHM, INCLUDE PSEUDOCODE WITH NUMBERED STEPS. IN YOUR CODE, CLEARLY COMMENT WHICH STEP IS BEING PERFORMED BY THE LINE OR BLOCK OF CODE. USE A TIMER TO CHECK HOW LONG EACH ALGORITHM TAKES TO SORT THE ARRAY. THIS SHOULD BE...

  • Radix sort C++ Come up with an unsorted array of numbers (integer array). Sort the numbers...

    Radix sort C++ Come up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order. USE THIS STUCTURE struct nodeQ{                            node *front;                            node *rear;               };               nodeQ que[10]; enqueue(que[i],data); EXAMPLE: Original, unsorted list: [170, 45, 75, 90, 2, 802, 24, 66] 1ST PASS:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT