Skip to content

Commit fb371eb

Browse files
sramakrishnan247thuva4
authored andcommitted
Implemented XorSwap in C (thuva4#539)
1 parent 5f88bc8 commit fb371eb

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,4 @@ Unfortunately, sometimes the bug can be only reproduced in your project or in yo
170170
- [ServinDC](https://github.com/ServinDC)
171171
- [Irshad Ismayil](https://github.com/irshadshalu)
172172
- [BrianChen](https://github.com/brianchen)
173+
- [S Ramakrishnan](https://github.com/sramakrishnan247)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ TernarySearch | :+1: |:+1: | | :+1: | :+1: | | | |
6767
Topological Sort | | | | | :+1: | | | |
6868
Segmented Sieve |:+1:| :+1: | | | :+1: | | | |
6969
Union Find |:+1:|:+1:| | :+1: | | | | |
70-
Xor swap |:+1:|:+1:| | | |:+1:|:+1:| |
70+
Xor swap |:+1:|:+1:| |:+1:| |:+1:|:+1:| |
7171
Connected-component labeling | | | | |:+1:| | | |
7272
Extended Euclidean algorithm | | | | |:+1:| | | |
7373

XorSwap/C/XorSwap.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdio.h>
2+
3+
void xorSwap (int *x, int *y) {
4+
if (x != y) {
5+
*x ^= *y;
6+
*y ^= *x;
7+
*x ^= *y;
8+
}
9+
}
10+
11+
int main(){
12+
int a,b;
13+
a=10;
14+
b=45;
15+
16+
printf("Values before Swap\n a=%d,b=%d\n",a,b);
17+
xorSwap(&a,&b);
18+
printf("Values after Swap\n a=%d,b=%d\n",a,b);
19+
}

0 commit comments

Comments
 (0)