Tuesday, December 21, 2021

String sorting using bubble sort

                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

Element of a good table (Ref: Database design mere mortals by Michael J. Hernandez)

  Elements of the Ideal Table: It represents a single subject, which can be an object or event that reduces the risk of potential data integ...