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...
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...
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...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort algorithm to sort this list. Fill in this table with each iteration of the loop in the selection sort algorithm. Mark the place from which you are looking for the 'next smallest element'. In this display, the upper numbers are the indices, the lower numbers are in the corresponding positions. Use the several rows provided to show the sequence of steps. 0 1 2...
This program is in C++, And please consider " sort pass #" for the output: Write...
This program is in C++, And please consider " sort pass #" for the output: Write a program that uses two identical arrays of eight integers. It should display the contents of the first array, then call a function to sort it using an ascending order bubble sort, modified to print out the array contents after each pass of the sort. Next the program should display the contents of the second array, then call a function to sort it using...