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
xxTIMURxx [149]
3 years ago
12

Finish and test the following two functions append and merge in the skeleton file:

Computers and Technology
1 answer:
avanturin [10]3 years ago
4 0

Answer:

Explanation:

#include <iostream>

using namespace std;

int* append(int*,int,int*,int);

int* merge(int*,int,int*,int);

void print(int*,int);

int main()

{ int a[] = {11,33,55,77,99};

int b[] = {22,44,66,88};

print(a,5);

print(b,4);

int* c = append(a,5,b,4); // c points to the appended array=

print(c,9);

int* d = merge(a,5,b,4);

print(d,9);

}

void print(int* a, int n)

{ cout << "{" << a[0];

for (int i=1; i<n; i++)

cout << "," << a[i];

cout << "}\n";

}

int* append(int* a, int m, int* b, int n)

{

int * p= (int *)malloc(sizeof(int)*(m+n));

int i,index=0;

for(i=0;i<m;i++)

p[index++]=a[i];

for(i=0;i<n;i++)

p[index++]=b[i];

return p;

}

int* merge(int* a, int m, int* b, int n)

{

int i, j, k;

j = k = 0;

int *mergeRes = (int *)malloc(sizeof(int)*(m+n));

for (i = 0; i < m + n;) {

if (j < m && k < n) {

if (a[j] < b[k]) {

mergeRes[i] = a[j];

j++;

}

else {

mergeRes[i] = b[k];

k++;

}

i++;

}

// copying remaining elements from the b

else if (j == m) {

for (; i < m + n;) {

mergeRes[i] = b[k];

k++;

i++;

}

}

// copying remaining elements from the a

else {

for (; i < m + n;) {

mergeRes[i] = a[j];

j++;

i++;

}

}

}

return mergeRes;

}

You might be interested in
Find every number from 1 to n (inclusive) that is a palindrome which starts with the digit 3. Do not user a helper function.
Mkey [24]

Answer: Following code is in python

n=input()

num='1'

while int(num)<=int(n):    //loop from 1 to n

   flag=1   //if an unequal element will be found it will be 0

   l=len(num)

   if num[0]=='3':

       j=0

       k=l-1

       while j<k:    //loop till middle of number

           if num[j]==num[k]:

               j+=1     //from beginning

               k-=1    //from end

           else:

               flag=0

               break

       if flag==1:

           print(int(num))

   num=str(int(num)+1)    //number will be incremented as integer

INPUT :

1000

OUTPUT :

3

33

303

313

323

333

343

353

363

373

383

393

Explanation:

In the above code, a loop is executed till num is equal to n which is entered by the user. num is treated as a string so that to ease the process of checking first character is 3 or not. If it is 3 then another loop executes which checks if an element from starting is equal to the corresponding element from the end. If an element is not equal then the flag is changed and then we break out of the loop and prints the number if the flag isn't changed.

7 0
3 years ago
Convert the following decimal number to its equivalent binary ,octal,hexadecimal 1920​
Serhud [2]

Answer:

0b11110000000 is binary

0o3600 is in octal

0x780 in hexa dec.

Explanation:its a bit complitcated to explain sorry bro!

3 0
3 years ago
The objective of this task is to use Scapy to estimate the distance, in terms of number of routers, between your VM and a select
Aleksandr [31]

Answer:

answer b

is correct

3 0
3 years ago
What concept or principle requires layered, complementary controls sufficient to detect and deter infiltration and exploitation
Alekssandra [29.7K]

Answer:

security In-depth

Explanation:

The security in depth is a principle in which a sequence of safeguarding channels is used to secure the important data and information i.e valuation to the company. It also increased the security for a company as a whole

Therefore in the given situation, the  security In-depth required to layered the safeguarding channels to detect the infiltration

Hence, the  security In-depth is the correct answer

4 0
3 years ago
Can you guys give some samples of STEM-related studies?​
anygoal [31]

Answer:

D :)))))

Explanation:

hope this helps

5 0
3 years ago
Read 2 more answers
Other questions:
  • The maximum number of colors that should be used on a slide is _____. 2 4 6 8
    12·2 answers
  • Impact of computer on education
    6·2 answers
  • IF YOU KNOW THE ANSWER TO THIS PLEASE ANSWER ASAP
    12·1 answer
  • What is called photo and video edition?
    8·1 answer
  • When you declare a string data type, you are actually creating an object from the?
    5·1 answer
  • WHICH OF THE FOLLOWING LOOKS JUST LIKE A CD ROM BUT CAN STORE MUCH MORE INFORMATION
    8·2 answers
  • When might be the best time to start saving for retirement?
    11·2 answers
  • Explain what is meant by information technology (IT). Explain what is meant by information systems (IS). Why is it important to
    7·1 answer
  • As marketing manager, you need to have ( blank) skills and (blank) skills.
    11·1 answer
  • What is the difference between skew and rotate in the MS Paint application?
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!