Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/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
单链表Java的插入排序_Java_Sorting_Linked List_Insertion Sort - Fatal编程技术网

单链表Java的插入排序

单链表Java的插入排序,java,sorting,linked-list,insertion-sort,Java,Sorting,Linked List,Insertion Sort,我正在尝试对链表类进行插入排序,以便按升序排序。我真的不确定我需要做什么。我找不到方法回到列表的开头 public static void LLInsertionSort (LinkedList LL){ IntNode currentNode = head; IntNode tail = null; while(currentNode != null&& tail != head ){ while (currentNode.get

我正在尝试对链表类进行插入排序,以便按升序排序。我真的不确定我需要做什么。我找不到方法回到列表的开头

public static void LLInsertionSort (LinkedList LL){

    IntNode currentNode = head;
    IntNode tail = null;
    while(currentNode != null&& tail != head ){


         while (currentNode.getData() > currentNode.getNext().getData()){

             int temp = currentNode.getData();
             currentNode.setData(currentNode.getNext().getData());
             currentNode.getNext().setData(temp);

每次都需要从列表中的第一个节点开始

public static IntList LLInsertionSort(Node head)
{
   IntNode current = head;
   IntNode tail = null;
   while(current != null&& tail != head )
   {
      IntNode next = current;
      for( ; next.next != tail;  next = next.next)
      {
        if(next.value <= next.next.value)
        {
          int temp = next.value;
          next.value = next.next.value;
          next.next.value = temp;
        }
      }
      tail = next;
      current = head;
   }
   return this;
}
公共静态IntList linsertionsort(节点头)
{
节点电流=头;
IntNode tail=null;
while(当前!=null&&tail!=head)
{
IntNode next=当前;
for(;next.next!=tail;next=next.next)
{

如果(next.value叹息)我肯定有一天它会与JavaScript相关,但……我想我们应该说与我们对死亡说的相同的话——不是今天。你的代码不完整。此外,你有一个变量
,虽然它的来源不明,但为什么不能使用它?还有,你为什么要交换节点
数据而不是重新组织节点?