可以参考下面的代码:
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))
链式存储是最常用的存储方式之一,它不仅可用来表示线性表,而且可用来表示各种非线性的数据结构。
参考资料来源:百度百科-单链表
从头到尾扫描一遍,记录最大值。
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;
}
//p为单链表头指针
int max=p->item;
p=p->next;
while(p!=NULL)
{
if(p->item>max)
max=p->item;
}
return max;