In: Computer Science
Write a C++ or Java code that does similar swap action:
def swap (Lst, indexA, indexB) :
t = Lst[indexA]
Lst[indexA] = Lst[indexB]
Lst[indexB] = t
L = [1,2,3,4,5,6,7,8,9,10]
i=3
j=7
print(L[i], L[j])
swap(L,i,j)
print(L[i],L[j])
#include <iostream>
using namespace std;
void swap(int Lst[], int indexA, int indexB){
int t = Lst[indexA];
Lst[indexA] = Lst[indexB];
Lst[indexB] = t;
}
int main() {
int L[] = {1,2,3,4,5,6,7,8,9,10};
int i=3, j=7;
cout<<L[i] <<" " <<L[j]<<endl;
swap(L,i,j);
cout<<L[i] <<" " <<L[j]<<endl;
}
======================
Done in C++, please CHECK...PLEASE COMMENT
THANKS, PLEASE COMMENT if there is any concern.