赞
踩
- #include <iostream>
- #include <climits>
- using namespace std;
-
- typedef struct ListNode{
- int val;
- ListNode* next;
- ListNode():val(0),next(nullptr){};
- ListNode(int x):val(x),next(nullptr){};
-
- }ListNode,*LinkList;
-
- LinkList TailInsertList(int n){
- ListNode* head = new ListNode ;
- ListNode* r = head;
- int x;
-
- for (int i = 0; i < n; ++i){
- cin>>x;
- ListNode * p = new ListNode (x);
- r->next = p;
- r = p;
- }
- r ->next = nullptr;
- return head;
- }
-
- int max_list(LinkList L){
- if(L == nullptr) return INT_MIN;
- int a = max_list(L->next);
- return a>L->val?a:L->val;
- }
-
- int main(){
- int n;
- while(cin>>n && n!=0){
- LinkList L = TailInsertList(n);
- cout<<max_list(L->next)<<endl;
- }
-
-
- return 0;
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。