SortedTrio - c =(tArr1.get(2 this.setFirst(a...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 import java.util.ArrayList public class SortedTrio <T extends Comparable<? super T>> extends Trio { public SortedTrio(){ //default constructor super() } public SortedTrio(T a, T b, T c){ // default setup, in case comparables fail, due to having multiples of the same. super(a,b,c) ArrayList<T> tArr1 = new ArrayList<T>() tArr1.add(a) tArr1.add(b) tArr1.add(c) T t1,t2 boolean swappedOnPrevRun = true while(swappedOnPrevRun) { swappedOnPrevRun = false for(int i = 0 { t1 = (tArr1.get(i)) t2 = (tArr1.get(i+1)) if(t1.compareTo(t2) > -1)// if current element is greater than the next { // swap the two elements swappedOnPrevRun = true // set element i+1 to where i used to be tArr1.set(i,t2) // release the old i into i+1 slot tArr1.set(i+1,t1) } } } a = (tArr1.get(0)) b = (tArr1.get(1))
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: c = (tArr1.get(2)) this.setFirst(a) this.setSecond(b) this.setThird(c) } public boolean contains(T a){ boolean value = false if(a == this.first() || a == this.second() || a == this.third()) value = true return value } public String toString() { Sheet1 Page 2 T one = (T)(this.first()) T two = (T)(this.second()) T three = (T)(this.third()) return "[" + one.toString() + ", " + two.toString() + ", " + three.toString() + "]" } } Sheet1 Page 3 // this variable keeps track of whether to continue sorting or exit i < tArr1.size() - 1 // we don't want the loop to end just yet, we're not done Sheet1 Page 4 Sheet1 Page 5 i++)// loop through every element in the array,except the last one Sheet1 Page 6...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern