Java program that implement bubble-sort and selection-sort sorting algorithms

1. Using Eclipse to develop the following Java program that implement bubble-sort and selection-sort sorting algorithms.

 

The following are skeletons of the bubble-sort and selection-sort algorithms:

Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now

 

Bubble sort:

 

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

 

                    for (int j = 0; j < array.length-1; j++)

 

                                if (array[j] >= array[j+1]) {

 

                                            int temp = array[j];

 

                                            array[j] = array[j+1];

 

                                            array[j+1] = temp;

 

                                }

 

 

 

Selection sort:

 

        for (int i = 0; i < array.length-1; i++) {

 

                    int maxIndex = 0;

 

                    int j;

 

                    for (j = 1; j < array.length-i; j++)

 

                                if (array[j] > array[maxIndex]) maxIndex = j;

 

                    int temp = array[maxIndex];

 

                    array[maxIndex] = array[j-1];

 

                    array[j-1] = temp;

 

        }

 

 

 

A sorting algorithm is stable if two data items or objects with equal key values, according to which sorting is performed, do not change their precedence order in the resulting sorted array. The above two sorting algorithms may not be stable sorting algorithms. Your task in this lab assignment is to use debugging techniques to detect unstableness of these two algorithms and fix the problem to make the algorithms become stable.

 

 

 

The following are you programming task and debugging task.

 

 

 

a)      In Eclipse, create a new Java project with name cs2043lab1.

 

b)      Write the following classes and interfaces.

 

·         Define a class called “StudentRecord” as follows:

 

class StudentRecord  {

 

            private String name, int grade;

 

            public StudentRecord(String name, int grade) {this.name = name; this.grade = grade;}

 

            public int getKey() {return grade;}

 

}

 

 

 

·         Define an interface called “Sorter” as follows:

 

interface Sorter {public void sort(StudentRecord[] students);}

 

 

 

·         Define a class called “BubbleSorter” that implement sorter interface as follows:

 

class BubbleSorter implements Sorter{public void sort(StudentRecord[] students){/*implement bubble sort algorithm*/}}

 

 

 

·         Define a class called “SelectSorter” that implement sorter interface as follows:

 

class SelectSorter implements Sorter{public void sort(StudentRecord[] students){/*implement selection sort algorithm*/}}

 

 

 

·         Define the main class called “Lab1App” with main method. The main method asks the user to input data to create multiple StudentRecord objects into an array, and also asks the user to Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code "Newclient" for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.