import java.io.*; class run { void sort(int a[],int n) { int i,j; for(i=0;i<n-1;i++) for(j=0;j<n-1-i;j++) if(a[j] > a[j+1]) { int temp = a[j]; a[j]=a[j+1]; a[j+1]=temp; } } public void display(int a[],int n) { for(int i=0;i<n;i++) System.out.print(a[i] + " "); } } public class bubble extends run { public static void main(String args[])throws IOException { System.out.print("\nProgram to sort array using bubble sort : \n"); int n,i; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("\nEnter array capacity : "); n=Integer.parseInt(br.readLine()); int a[]=new int[n]; for(i=0;i<n;i++) a[i]=(int)(Math.random()*100); run obj=new run(); System.out.print("\nArray before sorting : "); obj.display(a,n); obj.sort(a,n); System.out.print("\nArray after sorting : "); obj.display(a,n); } }
How to implement Bubble Sort using method call and inheritance in Java ?
Posted by
LAHAUL SETH
~
How to implement Bubble Sort using method call and inheritance in Java ?
2012-03-11T13:02:00+05:30
LAHAUL SETH
Java
|
Sorting
|
Comments (0)
How to implement Bubble Sort using method call and inheritance in Java ?
2012-03-11T13:02:00+05:30
LAHAUL SETH
Java
|
Sorting
|