Skip to content

Commit 163aa01

Browse files
Addd 2 more Question in Arrays
1 parent 0c843b0 commit 163aa01

File tree

5 files changed

+79
-1
lines changed

5 files changed

+79
-1
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
},
2121
"peacock.color": "#ff3d00",
2222
"files.associations": {
23-
"iostream": "cpp"
23+
"iostream": "cpp",
24+
"algorithm": "cpp"
2425
}
2526
}

Arrays/Unique-Element.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// Find Uniqe Element in Array :-
3+
4+
#include <iostream>
5+
6+
using namespace std;
7+
8+
int uniqueElement(int arr[], int size)
9+
{
10+
11+
int unique = 0;
12+
13+
for (int i = 0; i < size; i++)
14+
{
15+
unique = unique ^ arr[i]; // Jaab bhi hum XOR operator use krte hai to Same Value ko 0 kaar deta hai ,kyuki XOR operator ki property yehi hoti haiw
16+
}
17+
return unique;
18+
}
19+
20+
int main()
21+
{
22+
int arr[] = {4, 6, 6, 7, 4};
23+
int size = 5;
24+
25+
int result = uniqueElement(arr, size);
26+
cout << "The uniqe Element is : " << result << endl;
27+
28+
return 0;
29+
}

Arrays/Unique-Element.exe

43.7 KB
Binary file not shown.

Arrays/awap-alternate.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
// ! Alternate and Swap Question :-
3+
4+
#include <iostream>
5+
6+
using namespace std;
7+
8+
void swapAlternate(int arr[], int size)
9+
{
10+
// for (int i = 0; i < size - 1; i+=2) //! Simply Swap and Alternate
11+
for (int i = 0; i < size - 1; i += 3) // todo Wap for Swapping the every 3rd element
12+
{
13+
14+
int temp = arr[i];
15+
arr[i] = arr[i + 1];
16+
arr[i + 1] = temp;
17+
}
18+
}
19+
20+
void printArray(int arr[], int size)
21+
{
22+
for (int i = 0; i < size; i++)
23+
{
24+
25+
cout << arr[i] << " ";
26+
}
27+
28+
cout << endl;
29+
}
30+
31+
int main()
32+
{
33+
int arr[] = {1, 2, 3, 4, 5, 6};
34+
int size = 6;
35+
36+
cout << "Printing the Arrya Before Swap and alternate ";
37+
38+
printArray(arr, size);
39+
40+
swapAlternate(arr, size);
41+
42+
cout << "Printing The Array After Swap and Alternate ";
43+
printArray(arr, size);
44+
45+
swapAlternate(arr, size);
46+
47+
return 0;
48+
}

Arrays/awap-alternate.exe

43.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)