+ 2

I want to make a swap function i just dont know how.

Anyone got an idea of an algorithim to make swap function.

5th Nov 2020, 3:38 PM
ĴØ€ĴØ
ĴØ€ĴØ - avatar
6 Respostas
+ 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.
5th Nov 2020, 3:41 PM
Matthew
Matthew - avatar
+ 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.
5th Nov 2020, 3:46 PM
Arsenic
Arsenic - avatar
+ 3
Jan Markus Haha, nice and thoughtful way👏😋😊
5th Nov 2020, 4:58 PM
ĴØ€ĴØ
ĴØ€ĴØ - avatar
+ 2
Arsenic Yes i tried that one but it didn't work. Anyway thanks. 🤗
5th Nov 2020, 3:57 PM
ĴØ€ĴØ
ĴØ€ĴØ - avatar
+ 2
⟭⟬ ᦋꪶỉꪹꪖ⁷ ⟭⟬ I didnt know that. Thx alot.
5th Nov 2020, 3:58 PM
ĴØ€ĴØ
ĴØ€ĴØ - avatar
+ 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
5th Nov 2020, 5:00 PM
ĴØ€ĴØ
ĴØ€ĴØ - avatar