0
What's meant by swapping really ??
2 odpowiedzi
+ 2
In simple words swapping is nothing but exchanging the values stored in two variables. Consider x = 7 and y = 3 . And in the code if you exchange the value of x with y and y with x to get x =3 and y = 7 , you have sone swapping!
+ 1
U have at least two value, u wanna change the value. for example:
it is given:
int x = 1;
int y = 5;
and you want
int x= 5;
int y =1;
it is swap, change the value;
in order to chane , u need temporarily variable, like temp.
int temp = x; // here store x
x = y; // you can store in x the value of y
y = temp // because temp has the value of x