数据结构:单链表中求最大值的算法。

如题所述

可以参考下面的代码:

public static int FindMax(Node head)

{

if (head == null)

return 0;

int Max = head.value;

while(head.next != null)

{

if (head.next.value > Max)

Max = head.next.value;

head = head.next;

}

return Max;

扩展资料:

单链表的具体存储:

1、用一组任意的存储单元来存放线性表的结点(这组存储单元既可以是连续的,也可以是不连续的)

2、链表中结点的逻辑次序和物理次序不一定相同。为了能正确表示结点间的逻辑关系,在存储每个结点值的同时,还必须存储指示其后继结点的地址(或位置)信息(称为指针(pointer)或链(link))

链式存储是最常用的存储方式之一,它不仅可用来表示线性表,而且可用来表示各种非线性的数据结构。

参考资料来源:百度百科-单链表

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-01-04
从头到尾扫描一遍,记录最大值。追问

求详细的算法,非常感谢!

第2个回答  2012-01-04
public static int FindMax(Node head)
{
if (head == null)
return 0;
int Max = head.value;
while(head.next != null)
{
if (head.next.value > Max)
Max = head.next.value;

head = head.next;
}
return Max;
}
第3个回答  2012-01-04
//p为单链表头指针
int max=p->item;
p=p->next;
while(p!=NULL)
{
if(p->item>max)
max=p->item;
}
return max;追问

求算法?

追答

你其他的插入,初始化算法编好了??发给我看看,我要知道 你前面的算法

本回答被提问者采纳