单链表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相关,但……我想我们应该说与我们对死亡说的相同的话——不是今天。你的代码不完整。此外,你有一个变量头
,虽然它的来源不明,但为什么不能使用它?还有,你为什么要交换节点数据代码>而不是重新组织节点?