Sorting 单链表上的选择排序
我的算法……几乎……由于某种原因,排序后的最后两个元素顺序错误。另外,print语句没有显示Sorting 单链表上的选择排序,sorting,linked-list,Sorting,Linked List,我的算法……几乎……由于某种原因,排序后的最后两个元素顺序错误。另外,print语句没有显示first向右移动 public static SLL sort(SLL list) { SLLNode first = list.first ; SLLNode second ; while (first!=null) { System.out.println(first.data); // for seeing if first does move t
first
向右移动
public static SLL sort(SLL list)
{
SLLNode first = list.first ;
SLLNode second ;
while (first!=null)
{
System.out.println(first.data); // for seeing if first does move to the right
second = first.succ ;
while (second!=null)
{
if (second.data.compareTo(first.data)<0)
{
String temp = first.data ;
first.data = second.data ;
second.data = temp ;
}
second = second.succ ;
}
first = first.succ ;
}
return list ;
}
公共静态SLL排序(SLL列表)
{
SLLNode first=list.first;
SLLNode第二;
while(第一个!=null)
{
System.out.println(first.data);//用于查看first是否向右移动
第二个=第一个。成功;
while(秒!=null)
{
if(second.data.compareTo(first.data),因为大写的ascii值小于小写字母的ascii值
Also, the print statement does not show me that first moves to the right.
System.out.print(); // for seeing if first does move to the right
因为大写字母的ascii值小于小写字母的ascii值
Also, the print statement does not show me that first moves to the right.
System.out.print(); // for seeing if first does move to the right
另外,print语句没有显示first移到右侧。
System.out.print();//用于查看第一个是否向右移动
print()语句没有显示任何内容
另外,print语句没有显示first移到右侧。
System.out.print();//用于查看第一个是否向右移动
print()语句没有显示任何内容。如果只计划比较字符串,请使用compareToIgnoreCase
。或者,也可以使用System.String.Compare(stringA、stringB、true)
,参数bool
告诉函数它是否应该比较区分大小写。@n1.1,谢谢!知道为什么print语句没有给出我期望的结果吗?如果您只计划比较字符串,请使用compareToIgnoreCase
。或者,使用System.String.compare(stringA,stringB,true)
,bool
参数告诉函数是否应该比较区分大小写。@n1.1,谢谢!知道为什么print语句没有给出我所期望的吗?