Question

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

Homework Answers

Answer #1

#source code:

import java.util.*;

public class Test{

public static void bbs(int a[],int bbsl){

for(int i = 0; i < bbsl-1; i++){

for (int j = 0; j < bbsl-i-1; j++){

if(a[j]>a[j+1]){

int val=a[j];

a[j]=a[j+1];

a[j+1] = val;

}

}

}

}

public static void ins(int a[],int insl){

int out,i,j;

for (i=1;i<insl;i++){

out = a[i];

j = i - 1;

while (j >= 0 && a[j] > out){

a[j+1] = a[j];

j = j - 1;

}

a[j+1] = out;

}

}

public static void sss(int a[],int sssl){

int i,j;

for(i = 0; i < sssl-1; i++){

int mini = i;

for (j = i+1; j < sssl; j++)

if (a[j] < a[mini])

mini = j;

int out = a[mini];

a[mini] = a[i];

a[i] = out;

}

}

public static void sortarraysprint(int a[],int ttsl){

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

System.out.print(a[i]+" ");

}System.out.println("");

}

public static void main(String args[]){

int[] bs1={6,9,8,12,3,1,7};

int[] ss1={6,9,8,12,3,1,7};

int[] is1={6,9,8,12,3,1,7};

bbs(bs1,7);

sortarraysprint(bs1,7);

ins(ss1,7);

sortarraysprint(ss1,7);

sss(is1,7);

sortarraysprint(is1,7);

}

}

#output:

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
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...
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) {...
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.
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?
In JAVA Find the code for sorts in your language some where online. You will copy...
In JAVA Find the code for sorts in your language some where online. You will copy code from the internet (with citation!) and modify it to test. Make a random array of integers, then perform each search on them. LINEAR SEARCH Write a linear search method to find a number in the list. Call this before each of your sort methods. Include a comment explaining how Linear Search works, when to use it, when you cannot. BINARY SEARCH Write a...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is random? b. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is 90% sorted? c. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is reverse sorted? d. Which sorting methods perform best and...
# data structure Recall that the Insertion sort algorithm (for sorting an array A) from low...
# data structure Recall that the Insertion sort algorithm (for sorting an array A) from low to high has the skeleton form: for (i = 1; i < A.length; i++) { details omitted } For i = 1 to 6, show how the contents of the array is rearranged if at all) after each iteration of the for-loop. (10 pts) the original array A                                            A 6. 4. 7. 5....
Question 4: (20 marks) Given the following numbers found in an array: 8, 7, 1, 4,...
Question 4: Given the following numbers found in an array: 8, 7, 1, 4, 3, 9 Use insertion sort to sort the original list of numbers. Use bubble sort to sort the original list of numbers.   
Consider the following insertion sort algorithm. void insertion_sort(element a[], int n) // Put a[0]..a[n-1] into ascending...
Consider the following insertion sort algorithm. void insertion_sort(element a[], int n) // Put a[0]..a[n-1] into ascending order by insertion sort. { for (int k = 1; k < n; k++) { // At this point, a[0]..a[k-1] are already in order. // Insert a[k] where it belongs among a[0]..a[k]. You need to write code for this insertion as the body of the for-k loop. }//endfor k } a) Write the code for the body of the for-k loop to complete the...