File tree 1 file changed +47
-0
lines changed
1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ #include < iostream>
3
+ using namespace std ;
4
+ struct Array {
5
+ int * A;
6
+ int size;
7
+ int length;
8
+ };
9
+
10
+ // Finding duplicate for unsorted array
11
+ void Count_duplicate_unsorted (struct Array * arr) {
12
+
13
+ for (int i = 0 ; i < arr->length - 1 ; i++) {
14
+ int count = 1 ; // intializing count as 1
15
+ if (arr->A [i] != -1 ) { // if element is already checkd then dont go for checking the elements
16
+ for (int j = i + 1 ; j < arr->length ; j++)
17
+ {
18
+ if (arr->A [i] == arr->A [j]) // if duplicate element is found
19
+ {
20
+ count++; // increament the count
21
+ arr->A [j] = -1 ; // and mark element as -1 so that next time it won't confuse
22
+ }
23
+ }
24
+ if (count > 1 ) // if count is greater then i.e there is duplicate element
25
+ cout << arr->A [i] << " is appearing for " << count << " Times" << endl;
26
+ }
27
+ }
28
+ }
29
+ int main () {
30
+ struct Array arr;
31
+ int no;
32
+ cout << " Enter the size of the array " << endl;
33
+ cin >> arr.size ;
34
+ arr.A = new int [arr.size ];
35
+ arr.length = 0 ;
36
+ cout << " Enter the size of the array" << endl;
37
+ cin >> no;
38
+ cout << " Enter the elements of the array " << endl;
39
+ for (int i = 0 ; i < no; i++)
40
+ cin >> arr.A [i];
41
+ arr.length = no;
42
+ Count_duplicate_unsorted (&arr);
43
+ return 0 ;
44
+
45
+ }
46
+ // --------------------------------------------------------------------------------------------
47
+
1
48
#include < iostream>
2
49
using namespace std ;
3
50
int main ()
You can’t perform that action at this time.
0 commit comments