.[题目分析]本题明确指出单链表带头结点其结点数据是正整数且不相同要求利用直接插入原则把链表整理成递增有序链表这就要求从第二结点开释将各结点依次插入到有序链表中
LinkedList LinkListInsertSort(LinkedList la)∥la是带头结点的单链表其数据域是正整数本算法利用直接插入原则将链表整理成递增的有序链表
{if(la>next!=null)∥链表不为空表
{p=la>next>next;∥p指向第一结点的后继
la>next>next=null;∥直接插入原则认为第一元素有序然后从第二元素起依次插入
while(p!=null)
{r=p>next;∥暂存p的后继
q=la;
while(q>next!=null&&q>next>data<p>data)q=q>next;∥查找插入位置
p>next=q>next;∥将p结点链入链表
q>next=p;
p=r;
}
与本题有类似叙述的题的解答
()本题也是链表排序问题虽没象上题那样明确要求利用直接插入的原则来排序仍可用上述算法求解这里不再赘述
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []