.[题目分析] 题目要求按递增次序输出单链表中各结点的数据元素并释放结点所占存储空间应对链表进行遍历在每趟遍历中查找出整个链表的最小值元素输出并释放结点所占空间;再查次最小值元素输出并释放空间如此下去直至链表为空最后释放头结点所占存储空间当然删除结点一定要记住该结点的前驱结点的指针
void MiniDelete(LinkedList head)∥head是带头结点的单链表的头指针本算法按递增顺序输出单链表中各结点的数据元素并释放结点所占的存储空间
{while(head>next!=null)∥循环到仅剩头结点
{pre=head;∥pre为元素最小值结点的前驱结点的指针
p=pre>next;∥p为工作指针
while(p>next!=null)
{if(p>next>data<pre>next>data)pre=p;∥记住当前最小值结点的前驱
p=p>next;
}
printf(pre>next>data);∥输出元素最小值结点的数据
u=pre>next;pre>next=u>next; free(u);∥删除元素值最小的结点释放结点空间
}∥ while(head>next!=null)
free(head);}∥释放头结点
[算法讨论] 算法中使用的指针变量只有prep和u三个请读者细心体会要注意没特别记最小值结点而是记其前驱
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []