From 8ff4134c04dd44a30a89bf2a9b0ccf79e9259dec Mon Sep 17 00:00:00 2001 From: santosh palande <55282153+i-am-santosh17@users.noreply.github.com> Date: Fri, 20 Aug 2021 01:17:10 +0530 Subject: [PATCH] chore(CPlusPlus): added remove-duplicates (#416) Co-authored-by: Santosh --- .../CPlusPlus/Arrays/remove-duplicates.cpp | 64 +++++++++++++++++++ algorithms/CPlusPlus/README.md | 1 + 2 files changed, 65 insertions(+) create mode 100644 algorithms/CPlusPlus/Arrays/remove-duplicates.cpp diff --git a/algorithms/CPlusPlus/Arrays/remove-duplicates.cpp b/algorithms/CPlusPlus/Arrays/remove-duplicates.cpp new file mode 100644 index 00000000..34b6720d --- /dev/null +++ b/algorithms/CPlusPlus/Arrays/remove-duplicates.cpp @@ -0,0 +1,64 @@ +/*CPP program to remove the duplicate elements from the array in place + without using any extra space. + + The time complexity of the algorithm is: O(n) +Sample Example: +Input array size: 6 +Input array: 1 1 2 3 4 4 +output : 1 2 3 4 +*/ + +#include +using namespace std; + +// method to remove duplicate elements from array +void removeDuplicates(int arr[],int size){ + +int newsize=size; // variable to keep the track of size of array. + +for(int i=0,j=i+1;j>size; + // declare the array + int arr[size]; + // storing the minimum integer value for checking of array is sorted or not +int max=-2147483647; + + // get the sorted array from the user + cout<<"Enter the sorted array"<>arr[i]; + // checking if input array is sorted or not + if(arr[i]