ECSE 211 Lecture Notes - Lecture 2: Bubble Sort, Race Condition, Sorting Algorithm

71 views4 pages

Document Summary

//only occasion is if you have a method de ned for all vehicles, you need to pass a vehicle object to that method, then use this. //you would not need to create this interface, you can just use the one already implemented in. Java compareto() speci cation, need to provide documentation for the interface (e. g. compareto(a,b) compares a to b) public int compareto(object o); public class sorter { //why is sort taking comparable []? because comparable has the compareto method. public void sort (comparable [] array) { for (int i = 0; i < array. length; ++1){ //bubble sort int swapcount = 0; for (int j = 0; j < array. length -1; ++j){ if (array[j]. compareto(array[j+1]>0){ Comparable t = array[j] array[j] = array [j+1]; array [j +1] = t; swapcount ++; public class circle implements comparable{ private double radius; public circle (double radius) { this. radius = radius; public int compareto(object o){ return -1;

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents