MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / Leaders

Function Leaders

Arrays/32_Leaders_in_Array.cpp:22–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20#include<climits>
21using namespace std;
22void 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}
46int main()
47{
48 int len;

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected