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