Starting from:

$25

IT2650-Assignment 7 Collections (Arrays, Vectors, Lists,) Solved

The point of this assignment is to cover a few of the basic principles of collections and processing those collections.  

 

The solution for this assignment (at least the one I implemented) can be accomplished by inserting the code to perform a bubble sort on data entered by the user.

Using the IDE 

 

Initial Code & Output
 

Load the following code into the online compiler:

 

 

Please copy the following code into the IDE, compile and run it.

public class A07 { 

                     

                     // logic to sort the elements 

                    public static void bubbleSort(int array[]) { 

 

                    } 

                     

                    private static void swap(int i, int j, int[] array) { 

                                         int temp; 

  temp = array[i];   array[i] = array[j]; 

                                        array[j] = temp; 

                    } 

                     

                   private static void printArray(int[] input) { 

                                       for (int i = 0; i < input.length; i++) { 

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

                                        } 

                    } 

                     

                   public static void main(String[] args) { 

                         

                                       int[] input = { 4, 2, 9, 6, 23, 12, 34, 0, 1 }; 

                                         

        System.out.print("A07 - written by Matt Weisfeld\n\n"); 

        System.out.print("Initial Array:\n"); 

        printArray(input);         System.out.print("\n"); 

         

        System.out.print("\nIntermediate Steps:");                           bubbleSort(input); 

                                         

        System.out.print("\n\nSorted Array:\n");         printArray(input); 

                    } 

}     
     

This code covers a lot of programming concepts. Please take this opportunity to study the code and determine what is going on.

When you execute the code it will look something like this:

  

Problem
 

Note that the array is not sorted since the bubbleSort method is empty. This is a working application – now I want you to extend it and add some functionality.

 

All you need to do (and this is not trivial) is to add the code to sort arrays inside the following method:

 

public int[] bubble_srt (int array[])

 

Here are the constraints that you must include in your program.

1)     Include an output statement at the beginning of the program with the assignment number and your name:

A07 – Written by Matt Weisfeld

2)     The sort must be a bubble sort.

3)     Print out the initial array (already provided).

4)     Identify the number of the current pass (iteration) through the array.

5)     Print out the intermediate result of each pass (print routine already provided). 6) End the program when the array is completely sorted.

Note the number of steps will be different depending on the input array and the sort algorithm used. 

 

Final Output
 

Once completed, your output (in the following test case) should look like this:

  

           Note the input box is empty 

More products