String input = "geeksforgeeks";
char[] inputAr = input.toCharArray();
char temp;
for (int i = 0; i < inputAr.length ; i++) {// no of pass controller
for (int j = 0; j < inputAr.length -i- 1; j++) {
if (inputAr[j] > inputAr[j+1]) { //comparing with adjacent character.
temp = inputAr[j];
inputAr[j] = inputAr[j+1];
inputAr[j+1] = temp;
}
}
}
for (int i = 0; i < inputAr.length ; i++) {
System.out.println(inputAr[i]);
}
No comments:
Post a Comment