Answer to Question #54109 in C++ for Guruwinder

Question #54109
Consider A,B,C as three arrays of size m,n and m+n respectively. Array A is stored in ascending order where as array B is stored in descending order. Write a c++ program to produce a third array C, containing all the data of arrays A and B and arranged in descending order. Display the data of array C only.
1
Expert's answer
2015-08-14T02:57:13-0400
#include <iostream>

using namespace std;

void BubbleSort(int* arr, int size);

int main() {

const int n = 7;
const int m = 6;
int A[] = {45, 47, 55, 78, 81, 90, 102};
int B[] = {134, 122, 116, 90, 71, 34};

int* C = new int [n+m];

for (int i = 0; i < n+m; i++) {
if (i >= n)
C[i] = B[i - n];
else
C[i] = A[i];
}

BubbleSort(C, n+m);

cout<<"C : ";

for (int i = 0; i < n+m; i++)
cout<<C[i]<<" ";

cout<<endl;

cin.get();

return 0;
}


void BubbleSort(int* arr, int size)
{
int tmp;

for(int i = 0; i < size - 1; ++i)
{
for(int j = 0;j < size - 1; ++j)
{
if (arr[j + 1] > arr[j])
{
tmp = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = tmp;
}
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS