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
In Java: Create a bubble, insertion, selection sort algorithm that sorts the following: 6 9 8...
In Java: Create a bubble, insertion, selection sort algorithm that sorts the following: 6 9 8 12 3 1 7
Write a program to implement bubble sort, insertion sort, selection sort, merge sort and quick sort...
Write a program to implement bubble sort, insertion sort, selection sort, merge sort and quick sort (pivot = first index) algorithms. Compute the CPU processing time for all the algorithms for varying input sizes as follows: N = 102, 103, 104, 105, and 106 Use a random number generator to generate the inputs. Obtain the inputs from the following input ranges: 1- 103, 1 - 106, 1 – 109, 1 - 1012 Write down your results as a table (with...
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.
Develop an Algorithm and java program using Design Recipe: 1) Develop a java program to the...
Develop an Algorithm and java program using Design Recipe: 1) Develop a java program to the content of one file to another. Hint 1: read() Hint 2: write() 2) Develop a java program to List all files in a given directory. Hint: list()
Write a MATLAB program that implements the Insertion Sort algorithm. Test your implementation with this set...
Write a MATLAB program that implements the Insertion Sort algorithm. Test your implementation with this set of inputs: 16.2 32.7 -0.5 4.4 21.8 -17.0 6.9 14.1 1.5.
Java : Modify the selection sort algorithm to sort an array of integers in descending order....
Java : Modify the selection sort algorithm to sort an array of integers in descending order. describe how the skills you have gained could be applied in the field. Please don't use an already answered solution from chegg. I've unfortunately had that happen at many occasion ....... ........ sec01/SelectionSortDemo.java import java.util.Arrays; /** This program demonstrates the selection sort algorithm by sorting an array that is filled with random numbers. */ public class SelectionSortDemo { public static void main(String[] args) {...
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                                                                    
Given the recursive bubble sort algorithm, analyze its time complexity in terms of Big O. bubbleSort(A[],...
Given the recursive bubble sort algorithm, analyze its time complexity in terms of Big O. bubbleSort(A[], n) { // Base case if (n == 1) return;    // One pass of bubble sort. After // this pass, the largest element // is moved (or bubbled) to end. for (i=0; i<n-1; i++) if (A[i] > A[i+1]) swap(A[i], A[i+1]);    // Largest element is fixed, // recur for remaining array bubbleSort(A, n-1); }
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT