+ 2
I want to make a swap function i just dont know how.
Anyone got an idea of an algorithim to make swap function.
6 ответов
+ 9
https://www.programiz.com/cpp-programming/examples/swapping
See this 👆🏻
The function std::swap() is a built-in function in the C++ Standard Template Library (STL) which swaps the value of two variables. Parameters: The function accepts two mandatory parameters a and b which are to be swapped. The parameters can be of any data type.
+ 6
Think of it as switching liquid between 2 vessels.{v1 and v2}
First you would need an extra third vessel{v3} to empty one{say v1} and then pour liquid from {v2} to {v1} then from {v3} to {v2}.
Just apply this in programming where vessels are nothing but variables.
P.S. there are other ways also to swap them even without the third variable. I leave that for you to explore.
+ 3
Jan Markus
Haha, nice and thoughtful way👏😋😊
+ 2
Arsenic
Yes i tried that one but it didn't work.
Anyway thanks. 🤗
+ 2
⟭⟬ ᦋꪶỉꪹꪖ⁷ ⟭⟬
I didnt know that.
Thx alot.
+ 2
Jan Markus
⟭⟬ ᦋꪶỉꪹꪖ⁷ ⟭⟬
Arsenic
Thx alot you guys🤗.
Here i used the swap function for my first time.
I'd love to get your comments on it.
https://code.sololearn.com/cSlo9gGM3pPG/?ref=app