Aslistarr input array list whiletrue mid value

This preview shows page 2 - 3 out of 3 pages.

ArrayList<CheckAcc> arrayList = new ArrayList(Arrays.asList(arr)); //Input array list while(true){ mid = SearchBalanceAlgorithm(arrayList, value); if(mid == -1) break; CheckAcc obj = arrayList.get(mid); askedObjects.add(obj);
Image of page 2

Subscribe to view the full document.

arrayList.remove(mid); } System.out.println("After searching"); for(int i=0;i<askedObjects.size();i++){ System.out.println(askedObjects.get(i).Balance); } } public static int SearchBalanceAlgorithm(ArrayList<CheckAcc> arrayList, double value){ int low = 0, high = arrayList.size()-1, mid= (low + high) / 2; while(low <= high && arrayList.get(mid).Balance != value) { if(arrayList.get(mid).Balance > value) { low = mid + 1; } else{//arr[mid] > searchValue high = mid -1; } mid= (low + high)/ 2; //integer division will truncate } if(low > high) { mid = -1; } return mid; } } class CheckAcc{ String AccNum; String Name; double Balance; public CheckAcc(String AccNum, String Name, double Balance){ this.AccNum =AccNum; this.Name = Name; this.Balance = Balance; } }
Image of page 3
You've reached the end of this preview.
  • Fall '08
  • STAFF
  • Writer, Void type, Alice, frank, 116, WriteAcc

{[ 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