#include "LinkList.cpp"
#include <bits/stdc++.h>
LinkNode *Maxnode(LinkNode *L) {
if(L->next== NULL)
return L;
else {
LinkNode *maxp;
maxp = Maxnode(L->next);
if(L->data > maxp->data)
return L;
else
return maxp;
}
}
int main() {
int a[] = {1,2,5,2,3,2};
LinkNode *L,*p;
int n = sizeof(a) / sizeof(a[0]);
L = CreateList(a,n);
DispList(L);
p = Maxnode(L);
cout << endl << "最大值为:" << p->data;
Release(L);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef struct Node {
int data;
struct Node *next;
} LinkNode;
LinkNode *CreateList(int a[],int n) {
if(n < 0)
return NULL;
LinkNode *head = (LinkNode *)malloc(sizeof(LinkNode));
LinkNode *p = (LinkNode *)malloc(sizeof(LinkNode));
p = head;
head->data = a[0];
int i = 0;
for(i = 1; i < n; i++) {
LinkNode *node = (LinkNode *)malloc(sizeof(LinkNode));
node->data = a[i];
p->next = node;
p = node;
}
p->next = NULL;
return head;
}
void DispList(LinkNode *ln) {
cout << " ";
if(ln != NULL){
cout << ln->data;
DispList(ln->next);
}
}
void Release(LinkNode *ln) {
if(ln->next == NULL)
return ;
else {
Release(ln->next);
free(ln);
}
}