Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 单链表上的选择排序_Sorting_Linked List - Fatal编程技术网

Sorting 单链表上的选择排序

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

我的算法……几乎……由于某种原因,排序后的最后两个元素顺序错误。另外,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 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语句没有给出我所期望的吗?