Monday, 19 December 2011

BubbleSort

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

}

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...