Question

Write a Java Program to bubble sort 10,20,15,0,6,7,2,1,-5,55. Including Algorithm flowchart of the program.

Write a Java Program to bubble sort 10,20,15,0,6,7,2,1,-5,55.

Including Algorithm flowchart of the program.

Homework Answers

Answer #1
public class BubbleSort {


    public static void bubbleSort(int[] array) {

        // outer for loop
        for (int i = 0; i < array.length; i++) {

            // inner for loop
            for (int j = 0; j < array.length - i - 1; j++) {

                if (array[j] > array[j + 1]) {
                    // swap the elements
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }

    }

    public static void main(String[] args) {

        int array[] = {10, 20, 15, 0, 6, 7, 2, 1, -5, 55};
        System.out.println("Before Sorting");
        for (int num : array) System.out.print(num + " ");
        System.out.println();

        bubbleSort(array);

        System.out.println("\nAfter Sorting");
        for (int num : array) System.out.print(num + " ");
        System.out.println();

    }
}

====================================================================

FLOW CHART ( Please fit the text in the box)

Know the answer?
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
Similar Questions
Bubble Sort Algorithm in Java in decreasing order
Bubble Sort Algorithm in Java in decreasing order
The bubble sort algorithm discussed in class is used to sort the following sequence of integers:...
The bubble sort algorithm discussed in class is used to sort the following sequence of integers: 47 29 1 9 5 23 • How many passes must the algorithm perform to guarantee the entire sequence is sorted? • What is the list obtained after the first pass? • What is the list obtained after the third pass? • What is the list obtained after the final pass?
Write a Java Program to insert sort 7, 1, 3, 2, 42, 76, 9, then write...
Write a Java Program to insert sort 7, 1, 3, 2, 42, 76, 9, then write the sorted sublist for each step.
Sort the given keys using Counting sort algorithm. Also write the algorithm.          4, 1, 0,...
Sort the given keys using Counting sort algorithm. Also write the algorithm.          4, 1, 0, 2, 1, 5, 0, 4                                                                    
In Java. Write a program that reads-in a times table-number. The program, using this table-number will...
In Java. Write a program that reads-in a times table-number. The program, using this table-number will produce the following report (as shown). The first item in the report is a number with starting value 1. Second column is the word “ X ” (representing the times symbol). Third column is the table-number (itself). Following is an equal sign “ = “ (representing a result). Last column is the result of the operation for that line or row which is the...
Why is insertion sort considered better than bubble sort and does it have any significant impact...
Why is insertion sort considered better than bubble sort and does it have any significant impact on the total run time for N where n is the number of data points? (java)
​​​​​​WRITE FLOWCHART AND PSEUDOCODE ONLY (C++) Write the flowchart and pseudocode for the following program (but...
​​​​​​WRITE FLOWCHART AND PSEUDOCODE ONLY (C++) Write the flowchart and pseudocode for the following program (but not the program itself.) In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides. ( sidea2 = sideb2 + sidec2 / sideb2 = sidea2 + sidec2 / …..) The program will read three side lengths from a text file, and then print the lengths along with...
Write out an algorithm (using a list of steps or a flowchart), for describing to someone...
Write out an algorithm (using a list of steps or a flowchart), for describing to someone how to take the derivative of a polynomial of order n. ?(?) = ?0 + ?1? 1 + ?2? 2 + ⋯ + ??? ?
Please answer in C++ with the correct files (in bold). Thanks! Write a program that creates...
Please answer in C++ with the correct files (in bold). Thanks! Write a program that creates three identical arrays, list1, list2, and list3, of 5000 elements. The program then sorts list1 using bubble sort, list2 using selection sort, and list3 using insertion sort and outputs the number of comparisons and item assignments made by each sorting algorithm. Please use the file names listed below since your file will have the following components: Ch18_Ex15.cpp searchSortAlgorithms.h
1.        A. Write a recursive brute force algorithm that calculates an. B. Write the java code...
1.        A. Write a recursive brute force algorithm that calculates an. B. Write the java code that does the calculation. C. What is the recurrence relation for the number of multiplications? D. What is the efficiency class of the algorithm?