Question: //trying to sort an array of integers , need to use the Comparable Interface as implemented in my code but having problem passing array into

//trying to sort an array of integers , need to use the Comparable Interface as implemented in my code but having problem passing array into sort function and then returning the array back from it. //Best Regards

public class mySelection { public static void sort(Comparable[] ourArray) { int N= ourArray.length; for(int i=0; i < N; i++ ) { int min = i; //this is our minimum index but it starts from index 0 due to i; for(int j= i+1; j < N; j++) { //if( ourArray[j] < ourArray[min] ) // dikkat et comparable kullaniyorsun HAYTA !! boyle yapmiosunuz artik if(less(ourArray[j],ourArray[min])) { min= j; } } exch(ourArray, i, min);} } private static void exch(Comparable[] ourArray, int i, int j) { Comparable swap= ourArray[i]; ourArray[i]= ourArray[j]; ourArray[j]= swap; }

private static boolean less(Comparable v, Comparable w) { return ( v.compareTo(w)<0 ) ; }

public static void main(String[] args) { Comparable[] ourArray= { 1, 0, 3, 5, 9, 10 }; int ourSortedArray[] = sort(ourArray); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!