Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that asks user for their input of number of elements to be sorted and then uses bubbleSort to sort them. BubbleSort is

Write a program that asks user for their input of number of elements to be sorted and then uses bubbleSort to sort them. BubbleSort is a sorting algorithm.

//Use Appropriate imports here.

public class bubbleSortArrayList {

public static void main(String[] args) {

ArrayList items = new ArrayList<>();

Scanner inp = new Scanner(System.in);

//Ask the user for how many elements to be added.

System.out.println("Enter the number of elements to be added");

int HowManyElements = inp.nextInt();

//Complete the for loop for adding the elements to the ArrayList.

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

}

//Print out the Original ArrayList after user input Here.

/* Call the non-static bubbleSort method using the instantiated object 'list' of the class it is defined */

list.bubbleSort(items);

}

/*Complete the BubbleSort Algorithm as per the ArrayList usage and methods. Remember, the way to access the index elements is different in arrayLists than in Arrays. */

public void bubbleSort (){

for (){

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

if(){

int temp =;

;

;

}

}

}

//Print out the Sorted ArrayList Here.

}

}

}

Step by Step Solution

3.34 Rating (157 Votes )

There are 3 Steps involved in it

Step: 1

Answer import javautilArrayList import javautilScanner public class Bub... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Matlab An Introduction with Applications

Authors: Amos Gilat

5th edition

1118629868, 978-1118801802, 1118801806, 978-1118629864

More Books

Students also viewed these Operating System questions

Question

5t-6, x 4 Given f(x)=x

Answered: 1 week ago