-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrings.java
More file actions
47 lines (32 loc) · 1.2 KB
/
Strings.java
File metadata and controls
47 lines (32 loc) · 1.2 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.*;
public class Strings {
public static void selectionSort( String[] array )
{
// Find the string reference that should go in each cell of
// the array, from cell 0 to the end
for ( int j=0; j < array.length-1; j++ )
{
// Find min: the index of the string reference that should go into cell j.
// Look through the unsorted strings (those at j or higher) for the one that is first in lexicographic order
int min = j;
for ( int k=j+1; k < array.length; k++ )
if ( array[k].compareTo( array[min] ) < 0 ) min = k;
// Swap the reference at j with the reference at min
String temp = array[j];
array[j] = array[min];
array[min] = temp;
}
}
public static void Insertionsort (String array[],int f){
String temp="";
for(int i=0; i< f ;i++){
for(int j=i+1; j< f ; j++){
if(array[i].compareToIgnoreCase(array[j])>0){
temp = array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
}
}