Jump to content

Photo

Need help with Recursive Bubble Sort Algorithm

bubble sort sorting algorithms

  • Please log in to reply
No replies to this topic

#1
OFFLINE   jordana17

jordana17

    Newbie

  • Members
  • Pip
  • 1 posts
0
Unknown

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;
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users