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
C++ Programming Question: Write a function that sorts a linked list. Use insertion, bubble, selection or...
C++ Programming Question: Write a function that sorts a linked list. Use insertion, bubble, selection or shell sort.
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...
Complete the following table by specifying algorithm efficiency for : Selection sort, Insertion sort, Binary search,...
Complete the following table by specifying algorithm efficiency for : Selection sort, Insertion sort, Binary search, and Linear search. (Efficiency can be one of : log n, n, n2). List algorithms from the most efficient (fastest) to the least efficient (slowest).    ALGORITHM EFFICENCY 1 most efficient (fastest) 2 3 4 least efficient (slowest)
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.
In C++ Create a program that uses only Selection Sort and Insertion Sort for the National...
In C++ Create a program that uses only Selection Sort and Insertion Sort for the National Football League list of current players Inputting data from a text file named "NFLplayers.txt" Only want the name of the player(first name then last name), their team name, and position they play. Example is: Patrick Mahomes, Chiefs, Quarterback Output lists to a text file along with how long it took to go through the Selection Sort and Insertion Sort and how many iterations it...
First, understand the Selection-sort algorithm below: Selection-sort(A: Array [1..n] of numbers) 1       for i=n down to...
First, understand the Selection-sort algorithm below: Selection-sort(A: Array [1..n] of numbers) 1       for i=n down to 2 2                position=i 3                for j=1 to (i–1) 4                          if A[j]>A[position] then position=j 5                if position ≠ i then 6                          temp=A[i] 7                          A[i]=A[position] 8                          A[position]=temp (4 points) If input A=[12,5,11,6,10,7,9,8], what will A be after the 3rd iteration of the outermost for loop of the Selection-sort algorithm completes? A=[__, __, __, __, __, __, __, __] (8 points) Modify the algorithm to solve the...
Selection-Sort( A[1..n] ) 1 2 3 4 5 6 7 8 9 10 // INPUT: A[1..n],...
Selection-Sort( A[1..n] ) 1 2 3 4 5 6 7 8 9 10 // INPUT: A[1..n], an array of any n numbers in unknown order integer i, j, m fori=1ton−1 do swap A[i] ↔ A[m] // OUTPUT: A[1..n], its numbers now sorted in non-decreasing order m=i for j = i to n do if A[j] < A[m] then m = j Give a proof that this algorithm sorts its input as claimed.
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?
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT