-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8_RemovingRepeatedElements.cpp
More file actions
83 lines (67 loc) · 1.65 KB
/
8_RemovingRepeatedElements.cpp
File metadata and controls
83 lines (67 loc) · 1.65 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include<iostream>
using namespace std;
int main ()
{
int A[10], B[10], n, i, j, k = 0;
cout << "Enter size of array : ";
cin >> n;
cout << "Enter elements of array : ";
for (i = 0; i < n; i++)
cin >> A[i];
for (i = 0; i < n; i++)
{
for (j = 0; j < k; j++)
{
if (A[i] == B[j])
break;
}
if (j == k)
{
B[k] = A[i];
k++;
}
}
cout << "Repeated elements after deletion : ";
for (i = 0; i < k; i++)
cout << B[i] << " ";
return 0;
}
// Method 2..
// C++ program to remove the
// duplicate elements from the array
// using STL in C++
// #include <bits/stdc++.h>
// using namespace std;
// // Function to remove duplicate elements
// void removeDuplicates(int arr[], int n)
// {
// int i;
// // Initialise a set
// // to store the array values
// set<int> s;
// // Insert the array elements
// // into the set
// for (i = 0; i < n; i++) {
// // insert into set
// s.insert(arr[i]);
// }
// set<int>::iterator it;
// // Print the array with duplicates removed
// cout << "\nAfter removing duplicates:\n";
// for (it = s.begin(); it != s.end(); ++it)
// cout << *it << ", ";
// cout << '\n';
// }
// // Driver code
// int main()
// {
// int arr[] = { 4, 2, 3, 3, 2, 4 };
// int n = sizeof(arr) / sizeof(arr[0]);
// // Print array
// cout << "\nBefore removing duplicates:\n";
// for (int i = 0; i < n; i++)
// cout << arr[i] << " ";
// // call removeDuplicates()
// removeDuplicates(arr, n);
// return 0;
// }