[英]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 我在Java中非常新,我需要整个排序算法....我可以找到对1D数组进行排序的方法,但是2D数组变得非常令人困惑。请帮助
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)
(这是一个D数组的代码:)但是我需要2 D之一(仅按列选择排序)
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
. 如果你有每个DNA序列是一个字符串,你有一个
List
的Strings
。 Then just sort the strings. 然后只需对字符串进行排序。
List<String> dnaSequences = new ArrayList<String>();
dnaSequences.add("AGCAGAAGCGGAGCTTTAAGATGAATATAAATC");
...
dnaSequences.add("AGCAGAAGCGGAGCTTTAAGATGAATATAAATC");
Collections.sort(dnaSequences);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.