| 20 | #include<climits> |
| 21 | using namespace std; |
| 22 | void Leaders(int* arr,int len) |
| 23 | { |
| 24 | for(int i=0;i<len;i++){ |
| 25 | bool isbig=true; //Initially assume that present element is greater than next element |
| 26 | for(int j=i+1;j<len;j++){ |
| 27 | // check for the next element if it is greater change then change flag "isbig" to false |
| 28 | if(!(arr[i]>=arr[j])){ |
| 29 | isbig=false; |
| 30 | break; |
| 31 | } |
| 32 | // if they are arranged as they should be as in the case of leaders then change the flag to true |
| 33 | // Or you can leave the flag unchanged as it is ....! |
| 34 | // In the below codes are added for better understanding and Workflow. |
| 35 | else{ |
| 36 | isbig=true; |
| 37 | continue; |
| 38 | } |
| 39 | } |
| 40 | if(isbig){ |
| 41 | // Print the element for Leaders..! |
| 42 | cout<<arr[i]<<" "; |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | int main() |
| 47 | { |
| 48 | int len; |