Question

In: Computer Science

Write a C++ or Java code that does similar swap action: def swap (Lst, indexA, indexB)...

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])

Solutions

Expert Solution

#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.


Related Solutions

Write a Java function to swap two integers.
Write a Java function to swap two integers.
Convert this code written in Python to Java: # Definition of a function isprime(). def isprime(num):...
Convert this code written in Python to Java: # Definition of a function isprime(). def isprime(num):     count=2;     flag=0;     # Loop to check the divisors of a number.     while(count<num and flag==0):         if(num%count!=0):             # Put flag=0 if the number has no divisor.             flag=0         else:             # Put flag=1 if the number has divisor.             flag=1         # Increment the count.         count=count+1     # Return flag value.     return flag # Intialize list. list=[]...
Convert this C++ code to Java code this code is to encrypt and decrypt strings of...
Convert this C++ code to Java code this code is to encrypt and decrypt strings of characters using Caesar cipher please attach samples run of the code #include <iostream> #include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <string> #define MAX_SIZE 200 void encrypt_str(char xyz[], int key); // Function prototype for the function to encrypt the input string. void decrypt_str(char xyz[], int key); // Function prototype for the function to decrypt the encrypted string. using namespace std; int main() { char input_str[MAX_SIZE];...
IN JAVA. Which sorting does in place sorting? Which sort does the minimum swap to order...
IN JAVA. Which sorting does in place sorting? Which sort does the minimum swap to order ascending /desendinf manner?
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ *...
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ * This program takes a puzzle board and returns true if the * board is solvable and false otherwise * * Example: board 3 6 4 1 3 4 2 5 3 0 * The goal is to reach the 0. You can move the number of spaces of your * current position in either the positive / negative direction * Solution for this game...
Write a java method to swap between two values in a singly linked list
Write a java method to swap between two values in a singly linked list
Please write the following swap functions and print code in main to show that the functions...
Please write the following swap functions and print code in main to show that the functions have adequately . Your code should, in main(), print the values prior to being sent to the swap function. In the swap function, the values should be swapped and then in main(), please print the newly swapped values. 1) swap integer values using reference parameters 2) swap integer values using pointer parameters 3) swap pointers to integers - you need to print the addresses,...
Question #1 (Java) - Which sorting does in-place sorting? - Which sort does the minimum swap...
Question #1 (Java) - Which sorting does in-place sorting? - Which sort does the minimum swap to order ascending/descending manner? Note: I just need a short answer to the question no code.
Code: please use in visual studio 2019 c++ (not java) In total you will write 6...
Code: please use in visual studio 2019 c++ (not java) In total you will write 6 functions: Functions : A ) addInts, returns int; input is two ints; Add the values of the two parameters and return the sum B) subInts , returns int; input is two ints; Subtract the values of the two parameters and return the difference C) multInts, returns int; input is two ints; multiple the values of the two parameters and return the product D) divInts,...
Write a c program Write a function to swap two elements of an integer array. Call...
Write a c program Write a function to swap two elements of an integer array. Call the function to swap the first element, i[0] with last element i[n], second element i[1] with the last but one element i[n-1] and so on. Should handle arrays with even and odd number of elements. Call the swap function with the following arrays and print results in each case before and after swapping. i. int arr1[] = {0, 1, 2, 3, 30, 20, 10,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT