Please help me what is wrong. It doesn\'t like the compareTo :( please give //no
ID: 642592 • Letter: P
Question
Please help me what is wrong. It doesn't like the compareTo :( please give //notes as too what was wrong so I know for future refrence
___________________________________________________________________
import java.io.*;
import java.util.*;
public class T
{
int position, scan,p=-1;
void bubbleSort(T[] data)
{
for (position=0; position<=data.length -1; position++)
{
if(p+1==position)
{
for (scan=0; scan <= position -1;scan++)
{
if (data[scan].compareTo(data[scan+1])>0)
{
swap(data,scan,scan+1);
p=position;
}
}
}
else
{
println("List is sorted");
System.exit(0);
}
}
}
}
Explanation / Answer
import java.util.Scanner; class BubbleSort { public static void main(String []args) { int n, c, d, swap; Scanner in = new Scanner(System.in); System.out.println("Input number of integers to sort"); n = in.nextInt(); int array[] = new int[n]; System.out.println("Enter " + n + " integers"); for (c = 0; cRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.