0

I/P : Input array[] = {4.0, 6.5, 34.0, 2.0, 56.0, 73.0, 5.0, -5.0, 22.0, 45.0, 52.0, 42.0, 421.0}
O/P: Sorted array[] = {-5.0, 2.0, 4.0, 5.0, 6.5, 22.0, 34.0, 42.0, 45.0, 52.0, 56.0, 73.0, 421.0}

Sorted array using bubble sort.

public class BubbleSort {

double[] getBubbleSort(double[] values) {
return new double[] {};
}
}

I have to maintain the given code structure.
It is simple but I don't understand, how will I return a new double array of sorted values?
Please give me a hint for this type of return statement.

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by javaAddict
0

Yes I know it, but I have to maintain this return statement, so, I can not return a double array which have already been declared previously in that method. So, please give me a hint how to create a double array initialized by a old array at the time of creation.

0

Try something like this:

double[] getBubbleSort(double[] values) {
  double [] newArray = new double[values.length];
  for (int i=0;i<values.length;i++) {
    newArray[i] = values[i];
  }
  //your code here
  return newArray;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.