#include <stdio.h>
#include <stdlib.h>
#define N 5
typedef struct list
{
int data;
struct list *next;
}LNode;
LNode *creatlist(int *a)
{
LNode *h,*p,*q;
int i;
h=p=(LNode *)malloc(sizeof(LNode));
for(i=0; i<N; i++)
{
q=(LNode *)malloc(sizeof(LNode));
q->data=a[i];
p->next=q;
p=q;
}
p->next=0;
return h;
}
void outlist(LNode *h)
{
LNode *p;
p=h->next;
if (p==NULL)
printf("\nThe list is NULL!\n");
else
{
printf("\nHead");
do {
printf("->%d",p->data);
p=p->next;
} while(p!=NULL);
printf("->End\n");
}
}
int max(LNode *h)
{
LNode *p;
int max=-10000;
p=h->next;
while(p)
{
if(p->data>max)
{
max=p->data;
}
p=p->next;
}
return max;
}
int main()
{
LNode *A;
int a[N]={4,10,7,5,9};
A=creatlist(a);
printf("链表中的最大值:%d",max(A));
return 0;
}