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. https://www.youtube.com/watch?v=nmhjrI-aW5o&t=3s. BubbleSort

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

https://www.youtube.com/watch?v=nmhjrI-aW5o&t=3s.

BubbleSort is a sorting algorithm (Must have been taught in INFO 1112, or follow the video ). An ArrayList must be used to solve this question. Must use the template given below.

You cannot delete what is written as part of the code. But you can fill in the blanks. As far as possible avoid adding new variables.[10 Marks]

//Use Appropriate imports here. [1 Mark]

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. [3 Marks]

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

}

//Print out the Original ArrayList after user input Here. [1 Mark]

/* Call the non-static bubbleSort method using the instantiated object list of the class it is defined [1 Mark] */

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. [3 Marks]*/

public void bubbleSort (){

for (){

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

if(){

int temp =;

;

;

}

}

}

//Print out the Sorted ArrayList Here. [1 Mark]

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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