-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrd.cpp
More file actions
41 lines (34 loc) · 670 Bytes
/
rd.cpp
File metadata and controls
41 lines (34 loc) · 670 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
#include<iostream>
#include<cmath>
using namespace std;
int remdups(int arr[],int n){
//created temporary arr
int temp[n];
temp[0]=arr[0];
int res=1;
for(int i=1;i<n;i++){
if(temp[res-1]!=arr[i]){
temp[res]=arr[i];
res++;
}
}
for(int i=0;i<res;i++){
arr[i]=temp[i];
}
return res;
}
int main(){
int arr[]={10,20,20,30,30,30};
cout<<"Before Removal"<<endl;
int n;
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
//function
n=remdups(arr,n);
cout<<"After removal"<<endl;
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
}