1public static void swap(int x, int y, int[] arr) {
2 int temp = arr[x];
3 arr[x] = arr[y];
4 arr[y] = temp;
5}
1// swap strings
2#include <iostream>
3#include <string>
4
5main ()
6{
7 std::string buyer ("money");
8 std::string seller ("goods");
9
10 std::cout << "Before the swap, buyer has " << buyer;
11 std::cout << " and seller has " << seller << '\n';
12
13 seller.swap (buyer);
14
15 std::cout << " After the swap, buyer has " << buyer;
16 std::cout << " and seller has " << seller << '\n';
17
18 return 0;
19}