1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
irga5000 [103]
2 years ago
13

Merge arrays A and B into array C using merge sort algorithm. Give final sorted numbers of C using colored numbers without showi

ng intermediate steps. For example, your answer can be [1, 3, 3, 5, 7, 7, 9, 9, 13, 25] or [1, 3, 3, 5, 7, 7, 9,9, 13, 25), or another variation. void merge(int all, int aux[], int lo, int mid, int hi) / for (int k = lo; k<= hi; k++) aux [k] a[k]; int i lo, j = mid+1; for (int k lo; k<-hi; k++) if (i > mid) ak) else if (1 > hi) a[k] else if (small (aux(j), aux[1])) a[k] else ak aux[j++); aux (i++); aux [j++); /*++ aux (i++]; 1 j++
Computers and Technology
1 answer:
sweet-ann [11.9K]2 years ago
7 0

Answer:

Explanation:

Given code:-

#include<iostream>

using namespace std; //namespace

#define RED "\033[31m" /* Red */

#define BLUE "\033[34m" /* Blue */ //color definition

#define WHITE "\033[37m" /* White */

void mergeArrays(int arr1[], int arr2[], int n1, int n2, int arr3[])

//merger sort

{

int i = 0, j = 0, k = 0;

while (i<n1 && j <n2) //iterate over both array

{

if (arr1[i] < arr2[j]) //iff array 1 element is larger

{

arr3[k] = arr1[i]; //assign to a3

k++;

i++;

}

else

{

arr3[k] = arr2[j]; //else assign array 2 to a3

j++;

k++;

}

}

//say the array turns out to br of different sizes

//let us copy the remaining elemnt to array 3

while (i < n1)

{

arr3[k] = arr1[i];

i++;

k++;

}

while (j < n2)

{

arr3[k] = arr2[j];

k++;

j++;

}

}

int main(){

int A[4] = {3,5,7,9}; //array 1 assignment

int a_size = 4;

int b_size = 6;

int B[6] = {1,3,7,9,13,25}; //array 2 assignment

int C[10]; //array 3 declearation

int a_count = 0;

int b_count = 0; //counter for both array index

mergeArrays(A,B,a_size,b_size,C); //merger function applied;

cout<<WHITE<<"A: ";

for(int i = 0; i<4; i++){

cout<<RED<<A[i]<<" ";

}

cout<<endl<<WHITE<<"B: ";

for(int i = 0; i<6; i++){

cout<<BLUE<<B[i]<<" ";

}

cout<<endl<<WHITE<<"C: ";

for(int i = 0; i<10; i++){ //iterate over C

if(C[i] == A[a_count] && a_count < a_size){

cout<<RED<<C[i]<<" ";

// if element is common in array 1 print in red

a_count++;

}

else if (C[i] == B[b_count] && b_count < b_size){

//say element was similar in array 2,  print in blue

cout<<BLUE<<C[i]<<" ";

b_count++;

}

}

cout<<endl;

}

You might be interested in
To celebrate earth day, the employees of a company plan to reduce their carbon footprint in the workplace. Identify the changes
andrew11 [14]
<span>Go paperless. 
Use natural lighting. 
Grow trees nearby. 
Reduce, reuse, and recycle. 
Carpool. 
</span>
5 0
3 years ago
Read 2 more answers
5)What are the differences in the function calls between the four member functions of the Shape class below?void Shape::member(S
Stells [14]

Answer:

void Shape :: member ( Shape s1, Shape s2 ) ; // pass by value

void Shape :: member ( Shape *s1, Shape *s2 ) ; // pass by pointer

void Shape :: member ( Shape& s1, Shape& s2 ) const ; // pass by reference

void Shape :: member ( const Shape& s1, const Shape& s2 ) ; // pass by const reference

void Shape :: member ( const Shape& s1, const Shape& s2 ) const ; // plus the function is const

Explanation:

void Shape :: member ( Shape s1, Shape s2 ) ; // pass by value

The s1 and s2 objects are passed by value as there is no * or & sign with them. If any change is made to s1 or s2 object, there will not be any change to the original object.

void Shape :: member ( Shape *s1, Shape *s2 ) ; // pass by pointer

The s1 and s2 objects are passed by pointer as there is a * sign and not & sign with them. If any change is made to s1 or s2 object, there will be a change to the original object.

void Shape :: member ( Shape& s1, Shape& s2 ) const ; // pass by reference

The s1 and s2 objects are passed by reference  as there is a & sign and not * sign with them. If any change is made to s1 or s2 object.

void Shape :: member ( const Shape& s1, const Shape& s2 ) ; // pass by const reference

The s1 and s2 objects are passed by reference  as there is a & sign and not * sign with them. The major change is the usage of const keyword here. Const keyword restricts us so we cannot make any change to s1 or s2 object.

void Shape :: member ( const Shape& s1, const Shape& s2 ) const ; // plus the function is const

The s1 and s2 objects are passed by reference  as there is a & sign and not * sign with them. const keyword restricts us so we cannot make any change to s1 or s2 object as well as the Shape function itself.

5 0
3 years ago
Technician A says that the TP sensor signal voltage should be about 0.5 volt at idle and increase to about 2.5 volts at wide-ope
swat32

Answer:

Both are right.

Explanation:

4 0
3 years ago
Descuss the five generations of Computer language
Fiesta28 [93]

Answer:

Explanation:

The programming language in terms of their performance reliability and robustness can be grouped into five different generations, First generation languages (1GL) Second generation languages (2GL) Third generation languages (3GL)

6 0
2 years ago
Which examples are credible sources that could be used for an essay on the environment? Pick all that apply.
ahrayia [7]

Answer:

article, website run by non profit, website for fed agency

8 0
3 years ago
Other questions:
  • On a spreadsheet, this is the term for a grouping of cells that touch each other and form a rectangle. An example of it would be
    13·1 answer
  • What is the formula equivalent to the function =SUM(B1:B5)? A. =B1+B5 B. =$B$1+$B$5 C. =B1+B2+B3+B4+B5 D. =$B$1+$B$2+$B$3+$B$4+$
    7·1 answer
  • Arrays are described as immutable because they are two dimensional. are arranged sequentially. can be reordered. cannot be chang
    11·1 answer
  • How all wheel drive works
    5·1 answer
  • How will you apply what you have learned in our topic today in a real life situation? Show your answers in the acronyms provided
    6·1 answer
  • There exists a data type Date with member function Increment that increments the current Date object by one. The ++ operator is
    7·1 answer
  • Which of the following behaviors does not harm a company if your employment is terminated?
    9·1 answer
  • What is the most common option for fighting radiation?
    14·1 answer
  • There is overlap in the subjects of study in the different information technology disciplines.
    5·2 answers
  • after adding a sound to a slide, the audio tools tab will allow you to apply artistic effects and quick styles to your sound ico
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!