From bcf40bdff8e870fd9276f39530add02cc4479724 Mon Sep 17 00:00:00 2001 From: Gourav1000 <92661507+Gourav1000@users.noreply.github.com> Date: Mon, 31 Oct 2022 11:33:50 +0530 Subject: [PATCH 1/2] Create LeadersInAnArray --- data_structures/Arrays/CPP/LeadersInAnArray | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 data_structures/Arrays/CPP/LeadersInAnArray diff --git a/data_structures/Arrays/CPP/LeadersInAnArray b/data_structures/Arrays/CPP/LeadersInAnArray new file mode 100644 index 0000000000..f82797248b --- /dev/null +++ b/data_structures/Arrays/CPP/LeadersInAnArray @@ -0,0 +1,27 @@ +#include +using namespace std; + +/*C++ Function to print leaders in an array */ +void printLeaders(int arr[], int size) +{ + for (int i = 0; i < size; i++) + { + int j; + for (j = i+1; j < size; j++) + { + if (arr[i] <=arr[j]) + break; + } + if (j == size) // the loop didn't break + cout << arr[i] << " "; +} +} + +/* Driver program to test above function */ +int main() +{ + int arr[] = {16, 17, 4, 3, 5, 2}; + int n = sizeof(arr)/sizeof(arr[0]); + printLeaders(arr, n); + return 0; +} From 5ce823e28d64c48862c46db43a10489bcf6a707b Mon Sep 17 00:00:00 2001 From: Gourav1000 <92661507+Gourav1000@users.noreply.github.com> Date: Mon, 31 Oct 2022 22:45:01 +0530 Subject: [PATCH 2/2] Rename LeadersInAnArray to LeadersInAnArray.cpp --- .../Arrays/CPP/{LeadersInAnArray => LeadersInAnArray.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename data_structures/Arrays/CPP/{LeadersInAnArray => LeadersInAnArray.cpp} (100%) diff --git a/data_structures/Arrays/CPP/LeadersInAnArray b/data_structures/Arrays/CPP/LeadersInAnArray.cpp similarity index 100% rename from data_structures/Arrays/CPP/LeadersInAnArray rename to data_structures/Arrays/CPP/LeadersInAnArray.cpp