Current streak:
0 days
Longest streak:
24 days
Less
More
College monthly badge
1 Time topper
College of Engineering Roorkee
// we can swap by taking a third variable
void swapNumber(int &a, int &b) {
int temp=0;
temp=a;
a=b;
b=temp;
}
// we can swap with our inbuilt swap function
void swapNumber(int &a, int &b) {
swap(a,b);
}
//using + and - operator
void swapNumber(int &a, int &b){
a=a+b;
b=a-b;
a=a-b;
}
//using * and / operator
void swapNumber(int &a, int &b){
a=a*b;
b=a/b;
a=a/b;
}
//using xor ^ operator
void swapNumber(int &a, int &b){
a=a^b;
b=a^b;
a=a^b;
}
//Kindly upvote if this helps you in any way.
// we can swap by taking a third variable
void swapNumber(int &a, int &b) {
int temp=0;
temp=a;
a=b;
b=temp;
}
// we can swap with our inbuilt swap function
void swapNumber(int &a, int &b) {
swap(a,b);
}
//using + and - operator
void swapNumber(int &a, int &b){
a=a+b;
b=a-b;
a=a-b;
}
//using * and / operator
void swapNumber(int &a, int &b){
a=a*b;
b=a/b;
a=a/b;
}
//using xor ^ operator
void swapNumber(int &a, int &b){
a=a^b;
b=a^b;
a=a^b;
}
//Kindly upvote if this helps you in any way.
// we can swap by taking a third variable
void swapNumber(int &a, int &b) {
int temp=0;
temp=a;
a=b;
b=temp;
}
// we can swap with our inbuilt swap function
void swapNumber(int &a, int &b) {
swap(a,b);
}
//using + and - operator
void swapNumber(int &a, int &b){
a=a+b;
b=a-b;
a=a-b;
}
//using * and / operator
void swapNumber(int &a, int &b){
a=a*b;
b=a/b;
a=a/b;
}
//using xor ^ operator
void swapNumber(int &a, int &b){
a=a^b;
b=a^b;
a=a^b;
}
//Kindly upvote if this helps you in any way.
// we can swap by taking a third variable
void swapNumber(int &a, int &b) {
int temp=0;
temp=a;
a=b;
b=temp;
}
// we can swap with our inbuilt swap function
void swapNumber(int &a, int &b) {
swap(a,b);
}
//using + and - operator
void swapNumber(int &a, int &b){
a=a+b;
b=a-b;
a=a-b;
}
//using * and / operator
void swapNumber(int &a, int &b){
a=a*b;
b=a/b;
a=a/b;
}
//using xor ^ operator
void swapNumber(int &a, int &b){
a=a^b;
b=a^b;
a=a^b;
}
//Kindly upvote if this helps you in any way.
// we can swap by taking a third variable
void swapNumber(int &a, int &b) {
int temp=0;
temp=a;
a=b;
b=temp;
}
// we can swap with our inbuilt swap function
void swapNumber(int &a, int &b) {
swap(a,b);
}
//using + and - operator
void swapNumber(int &a, int &b){
a=a+b;
b=a-b;
a=a-b;
}
//using * and / operator
void swapNumber(int &a, int &b){
a=a*b;
b=a/b;
a=a/b;
}
//using xor ^ operator
void swapNumber(int &a, int &b){
a=a^b;
b=a^b;
a=a^b;
}
//Kindly upvote if this helps you in any way.
dutch nationial flag algo basically deals with the thing that 0 is in beginning , 1 in mid and 2 in the end, you can see that easily in below code.
#include <bits/stdc++.h>
void sort012(int *arr, int n)
{
int low=0,high=n-1,mid=0;
while(high>=mid)
{
if(arr[mid]==0)
{
swap(arr[low],arr[mid]);
low++;
mid++;
}
else if(arr[mid]==1)
{
mid++;
}
else if(arr[mid]==2)
{
swap(arr[mid],arr[high]);
high--;
}
}
}
Kindly upvote if it helps you in anyway :)
dutch nationial flag algo basically deals with the thing that 0 is in beginning , 1 in mid and 2 in the end, you can see that easily in below code.
#include <bits/stdc++.h>
void sort012(int *arr, int n)
{
int low=0,high=n-1,mid=0;
while(high>=mid)
{
if(arr[mid]==0)
{
swap(arr[low],arr[mid]);
low++;
mid++;
}
else if(arr[mid]==1)
{
mid++;
}
else if(arr[mid]==2)
{
swap(arr[mid],arr[high]);
high--;
}
}
}
Kindly upvote if it helps you in anyway :)
dutch nationial flag algo basically deals with the thing that 0 is in beginning , 1 in mid and 2 in the end, you can see that easily in below code.
#include <bits/stdc++.h>
void sort012(int *arr, int n)
{
int low=0,high=n-1,mid=0;
while(high>=mid)
{
if(arr[mid]==0)
{
swap(arr[low],arr[mid]);
low++;
mid++;
}
else if(arr[mid]==1)
{
mid++;
}
else if(arr[mid]==2)
{
swap(arr[mid],arr[high]);
high--;
}
}
}
Kindly upvote if it helps you in anyway :)
dutch nationial flag algo basically deals with the thing that 0 is in beginning , 1 in mid and 2 in the end, you can see that easily in below code.
#include <bits/stdc++.h>
void sort012(int *arr, int n)
{
int low=0,high=n-1,mid=0;
while(high>=mid)
{
if(arr[mid]==0)
{
swap(arr[low],arr[mid]);
low++;
mid++;
}
else if(arr[mid]==1)
{
mid++;
}
else if(arr[mid]==2)
{
swap(arr[mid],arr[high]);
high--;
}
}
}
Kindly upvote if it helps you in anyway :)