Popular Posts

Monday, 16 December 2013

Posted by Unknown on 07:03 | No comments

public class Sorting { 
    public static void main(String[] args) {
        
    int j,key;
    char[]A ={'a','d','e','m','u','c','h','t','a','r'};
  
        for (char i = 0; i <A.length; i++) {
            key=A[i];
            j=i-1;
            while((j>=0) && (key<A[j])){
                A[j+1]=A[j];
                j=j-1;         
            }
            A[j+1]=(char) key;
            System.out.println(A[j+1]);
        } 
    }
  
}

Output:
run:
a
d
e
m
u
c
h
t
a
r
BUILD SUCCESSFUL (total time: 0 seconds)


0 comments:

Post a Comment

Search Our Site

Bookmark Us

Delicious Digg Facebook Favorites More Stumbleupon Twitter