Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package homework8;
- /**
- *
- * @author ben
- */
- public class BubbleSort implements Sort {
- int comparisons = 0;
- int swaps = 0;
- public void resetStats() {
- comparisons = 0;
- swaps = 0;
- }
- public int getNumComparisons() {
- return comparisons;
- }
- public int getNumSwaps() {
- return swaps;
- }
- public <T extends Comparable<T>> void sortHW8(T[] table) {
- int pass = 1;
- boolean exchanges = false;
- do{
- exchanges = false;
- for (int i = 0; i < table.length - pass; i++){
- if (table[i].compareTo(table[i + 1]) > 0){
- T temp = table[i];
- table[i] = table[i+1];
- table[i+1] = temp;
- exchanges = true;
- }
- }
- pass++;
- } while (exchanges);
- }
- public void sortHW8(int[] arr) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
- }
Add Comment
Please, Sign In to add comment