Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(JAVA) Does anybody could help me? Problem 1 Write down the bugs in the following code. 01 public void 3Sorts(E[] data, Comparator c) { 02

(JAVA) Does anybody could help me?

Problem 1

  • Write down the bugs in the following code.
01 public void 3Sorts(E[] data, Comparator c) { 02 for (int i = 0; i <= data.length; i++) { 03 for (int j = i; j < data.length; j++) 04 int temp = data[j]; 05 if (data[j] > data[j + 1]) { 06 swap(data[j], data[j + 1]; 07 } 08 } 09 } 10 } 11 12 13 private E getMinimum(E[] data, Comparator c) 14 int min = data[0]; 15 for (int i = 0; i < data.length; i += 2) { 16 if (c.compare(min, data[i]) < 0) { 17 min = data[i]; 18 } 19 } 20 return min; 21 }

Problem 2

Fix the bubble sort so that it has BigO(n) when it runs on a sorted array.

public void bubbleSort(E[] data, Comparator c) { for (int i = 0; i < data.length; i++) { for (int j = 0; j < data.length - i; j++) { if (c.compare(data[j], data[j + 1]) > 0) { swap(data[j], data[j + 1]); } } } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Publishing With Filemaker Pro On The Web

Authors: Maria Langer

1st Edition

0201696657, 978-0201696653

More Books

Students also viewed these Databases questions

Question

What is the distribution of B(s) + B(t), s t?

Answered: 1 week ago