forked from manavdoda7/CPP-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursivemax.cpp
More file actions
48 lines (39 loc) · 721 Bytes
/
recursivemax.cpp
File metadata and controls
48 lines (39 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<climits>
#include<bits/stdc++.h>
using namespace std;
class Node{
public:
int data;
Node *next;
};
int maximum(Node* n)
{ int x =0;
if(n == NULL){
return INT_MIN;
}
else{
x = maximum(n->next);
if(x>n->data){
return x;
}
else{
return n->data;
}
}
}
int main(){
Node *head = NULL;
Node *first = NULL;
Node *second = NULL;
head = new Node();
second = new Node();
first = new Node();
head->data = 1;
head->next = first;
first->data = 10;
first->next = second;
second->data = 3;
second->next = NULL;
cout<<maximum(head);
return 0;
}