java program 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:

 

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 Looking for a similar assignment? Our writers will offer you original work free from plagiarism. We follow the assignment instructions to the letter and always deliver on time. Be assured of a quality paper that will raise your grade. Order now and Get a 15% Discount! Use Coupon Code "Newclient"