answersLogoWhite

0

Is impossible without doing things you really shouldn't be doing. For example with strings you might try concatenating them together and splitting it back apart to accomplish a swap, or with integers you might be able to use math to do this. None of these techniques will generalize to an arbitrary data type, however, so my recommendation is:

Just use a third variable and do a standard swap:

Thing first = ...

Thing second = ...

Thing swap = first;

first = second;

second = swap; Is impossible without doing things you really shouldn't be doing. For example with strings you might try concatenating them together and splitting it back apart to accomplish a swap, or with integers you might be able to use math to do this. None of these techniques will generalize to an arbitrary data type, however, so my recommendation is:

Just use a third variable and do a standard swap:

Thing first = ...

Thing second = ...

Thing swap = first;

first = second;

second = swap;

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

Swapping of two variables withou using temp variable?

example: x = x-y; y = y-x; x = y-x; <><><> It is not possible to swap two variables without using a temp variable. The code in the answer above, while clever, does not swap the variables. It will exchange the variable values for certain values of x and y, e.g. when x and y are small integers. If x and y are other values, such as strings, pointers, Infinity, NaN (not a number), floating point, or near the limits of the representation (causing over/underflow) then the code will not "swap" the values. <---> Note: there is absolutely no point in swapping two variables without using temopral variable, it's just a typical homework question, already asked here countless times. Another variation: a ^= b; b ^= a; a ^= b;


When using goal seek command how many input variables can you change at a time?

Just one value can be changed.


Why do you use varibles in math?

Variables allow one to summarise a lot of information using just a variable and a related function.


How to make cake using sugar egg and chocolate only?

That is not possible by using just those three ingredients


How do you know that a variable is really a control variable and what is the property of control variables?

If you're performing an experiment in which your result depends on multiple variables, but you're just interested in how one of those variables effects the result, you would generally keep all of the other variables constant in order to negate their effects. Those variables that you're keeping constant are called control variables, and you would choose them based on the experiment. For example, say you wanted to determine how changes in resistance effect a circuit's current. Well, current is dependent on not only resistance, but voltage as well, and since you're only interested in the effects of resistance, you would make voltage the control variable, keeping it constant.


What is the complexity of reverse the input string using stack?

O(n*2) for n characters. It is more efficient to simply walk from both ends of the string, swapping characters as you go, reducing the complexity to just O(n/2).


What are the two variables in this problem 3n-n320?

-317


What is the converse of p only if q?

q only if p. The converse of a statement is just swapping the places of the two terms.


What are explanatory and response variables in statistics?

Explanatory and Response variables are just fancy words for independent and dependent variables. Explanatory is the independent variable and response is the dependent variable.


What is the Concept of swapping with only two variable?

Non-using of temporal variable. It is possible, but has no use in real programming. Eg. a := a XOR b b := a XOR b a := a XOR b I warn you again: this is just a curiosity, not something you really use.


Do you use an array when you only have two or three items to track?

Yes. Using an array when multiple elements need to be created at a time is always a better idea than declaring multiple variables. For ex: Int i, j, k; Int[] arr; I have declared 3 int variables and another array just below it. Here since we are using only 3 variables, we can manage to use them without issues but if the number crosses 5 or even more then definitely using an array is always the best option.


Why is m the slope and b the y-intercept?

As my math teacher would say, the Math gods just picked those random variables to represent these things. There is no specific reason to my knowledge.