
using a bubble sort, for each entry in the array, display the original index of the first dimension, the second dimension's value, and the first dimension's value on a single line separated by : (colon) sorted by the second dimension.
I already got the two dimensional array figured out just couldnt dont know how to plug in the bubble sort. Thanks in advace


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | public class BubbleSort { /** * @Author : Chandrasekhara Kota * @Date : 17-December-2011 */ public static void main(String[] args) { // TODO Auto-generated method stub int num[]={4,1,9,5,2,8,10}; for(int i=0;i<num.length;i++) { for(int y=0;y<num.length-1;y++) { if(num[y]>num[y+1]) { int temp=num[y+1]; num[y+1]=num[y]; num[y]=temp; } } } System.out.println("Sorted Data is :"); for(int i=0;i<num.length;i++) { System.out.print(" "+num[i]); } } } |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.