//比较函数
public int compareTo(KeyType another)
{
int thisVal=this.key;
int anotherVal=another.key;
return (thisVal<anotherVal? -1:(thisVal==anotherVal? 0:1));
}
public void insertSort()//调用该比较函数的方法:不带监视哨的插入排序方法
{
RecordNode temp;
int i,j;
for(i=1;i<this.curlen;i++)
{
temp=r[i];
for(j=i-1;j>=0&&temp.key.compareTo(r[j].key)<0;j--)
{
r[j+1]=r[j];
}
r[j+1]=temp;
}
}
String biao[]= {"20","25","9","15","30"};//创建的顺序表
15 20 25 30 9 //输出结果
你可以找一本英文字典,它的单词的排序就是字符串排序的规则:
(1)短字符在同样前缀的长字符前面,比如
a
about
(2)第一个字母相同,再比第二个字符,第二个相同再比第三个
abandon
about
(3)第一个不同,就看第一个,第一个相同,就看第二个……(不管再后面)
attribute
banana
回到你的问题
15和9比较,9比1大,所以就在后面