简体   繁体   中英

how to sort a two dimensional char array (only column wise) by selection sort in java

im very new in java i need the whole sorting algorithm....i can find ways to sort a 1 D array but a 2 D array gets very confusing.PLEASE help

sorry i dont have a code yet, i dont know where to start from! (this is the code for a one D array:) but i need one of 2 D (only column wise selection sort)

public static void sort(Comparable[] table) { 
int n = table.length; 
for (int fill=0; fill < n-1; fill++) { 


int posMin = fill; 
for(int next=fill; next < n; next++) { 
if(table[next].compareTo(table[posMin] < 0) {
posMin = next; 

} 
} 
//Exchange table[fill] and table[posMin] 
Comparable temp = table[fill]; 
table[fill] = table[posMin]; 
table[posMin] = temp; 


} 

从注释中听起来,您可以将每一列视为一维数组,因此可以将现有的一维解决方案应用于每一列:无论您引用table [x],现在都可以引用table [x] [c] ,其中c是要排序的列(或table [c] [x];不确定用于列的索引)。

If you have each DNA sequence be a string, you have a List of Strings . Then just sort the strings.

List<String> dnaSequences = new ArrayList<String>();
dnaSequences.add("AGCAGAAGCGGAGCTTTAAGATGAATATAAATC");
...
dnaSequences.add("AGCAGAAGCGGAGCTTTAAGATGAATATAAATC");
Collections.sort(dnaSequences);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM