Jump to content

Need help with Recursive Bubble Sort Algorithm


Recommended Posts

Hey,

M trying to implement bubble sort using recursion and have got a response ArrayIndexOutOfBoundsException: 11

 

Unable to figure out where I went wrong

public static int[] recBubSort(int []arr, int n){
if(n > arr.length-1){
return arr;
}

if(arr[n] > arr[n+1]){
swap(arr,n,n+1);
}
return recBubSort(arr,n+1);
}

public static void swap(int arr[], int minPos, int index) {
//System.out.println("SelectionSort SWAP...");
int temp = arr[minPos];
arr[minPos] = arr[index];
arr[index] = temp;
}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...