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
luda_lava [24]
4 years ago
6

Data Structure in C++

Computers and Technology
1 answer:
agasfer [191]4 years ago
4 0

The code .cpp is available bellow

#include<iostream>

using namespace std;

//declaring variables

void merge(int* ip, int sz, int* opt, bool opt_asc); //merging

int* mergesort(int* ip, int sz);

void mergesort(int *ip, int sz, int* opt, bool opt_asc);

void merge(int* ip, int sz, int* opt, bool opt_asc)

{

  int s1 = 0;

  int mid_sz = sz / 2;

  int s2 = mid_sz;

  int e2 = sz;

  int s3 = 0;

  int end3 = sz;

  int i, j;

   

  if (opt_asc==true)

  {

      i = s1;

      j = e2 - 1;

      while (i < mid_sz && j >= s2)

      {

          if (*(ip + i) > *(ip + j))

          {

              *(opt + s3) = *(ip + j);

              s3++;

              j--;

          }

          else if (*(ip + i) <= *(ip + j))

          {

              *(opt + s3) = *(ip + i);

              s3++;

              i++;

          }

      }

      if (i != mid_sz)

      {

          while (i < mid_sz)

          {

              *(opt + s3) = *(ip + i);

              s3++;

              i++;

          }

      }

      if (j >= s2)

      {

          while (j >= s2)

          {

              *(opt + s3) = *(ip + j);

              s3++;

              j--;

          }

      }

  }

  else

  {

      i = mid_sz - 1;

      j = s2;

      while (i >= s1 && j <e2)

      {

          if (*(ip + i) > *(ip + j))

          {

              *(opt + s3) = *(ip + i);

              s3++;

              i--;

          }

          else if (*(ip + i) <= *(ip + j))

          {

              *(opt + s3) = *(ip + j);

              s3++;

              j++;

          }

      }

      if (i >= s1)

      {

          while (i >= s1)

          {

              *(opt + s3) = *(ip + i);

              s3++;

              i--;

          }

      }

      if (j != e2)

      {

          while (j < e2)

          {

              *(opt + s3) = *(ip + j);

              s3++;

              j++;

          }

      }

  }

   

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

      *(ip + i) = *(opt + i);

}

int* mergesort(int* ip, int sz)

{

  int* opt = new int[sz];

   

  mergesort(ip, sz, opt, true);

  return opt;

}

void mergesort(int *ip, int sz, int* opt, bool opt_asc)

{

  if (sz > 1)

  {

      int q = sz / 2;

      mergesort(ip, sz / 2, opt, true);

      mergesort(ip + sz / 2, sz - sz / 2, opt + sz / 2, false);

      merge(ip, sz, opt, opt_asc);

  }

}

int main()

{

  int arr1[12] = { 5, 6, 9, 8,25,36, 3, 2, 5, 16, 87, 12 };

  int arr2[14] = { 2, 3, 4, 5, 1, 20,15,30, 2, 3, 4, 6, 9,12 };

  int arr3[10] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };

  int *opt;

  cout << "Arays after sorting:\n";

  cout << "Array 1 : ";

  opt = mergesort(arr1, 12);

  for (int i = 0; i < 12; i++)

      cout << opt[i] << " ";

  cout << endl;

  cout << "Array 2 : ";

  opt = mergesort(arr2, 14);

  for (int i = 0; i < 14; i++)

      cout << opt[i] << " ";

  cout << endl;

  cout << "Array 3 : ";

  opt = mergesort(arr3, 10);

  for (int i = 0; i < 10; i++)

      cout << opt[i] << " ";

  cout << endl;

  return 0;

}

You might be interested in
DigitalHealth Electronics Inc. is a company that builds diagnostic devices. It was the first company to develop a compact MRI sc
Lemur [1.5K]

Answer:

B) Architectural innovation

Explanation:

Based on the information provided within the question it seems that the type of innovation in which this scenario best illustrates is Architectural Innovation. This type refers to getting rid of a company's architectural knowledge but keeping the main core design of it's products. Which is what is happening in this situation since DigitalHealth Electronics Inc. decided to scrap the MRI design but keep its core concept in order to develop a smaller more compact version.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

7 0
4 years ago
The Hazard Communication Standard, commonly called the “Right-to-Know” law, gives you the right to know what information?
AlladinOne [14]
The answer to your question is D, OSHA requires employers to let employees of any hazardous chemicals exposed,or not.
7 0
3 years ago
Read 2 more answers
What is 38 - -93 + 2 x 4.6?<br> and what’s 9,220 - -2.3 x U
Degger [83]

Answer:

the first equation is 140.2

what's the last eqaution U???

Explanation:

7 0
3 years ago
Explain paragraph layout
S_A_V [24]

Answer:

introduction, body, resolution/conclusion.

3 0
3 years ago
What does it mean? It teaches kids to play instruments.
Nady [450]
Something that teaches children to play instruments so like 'it' could be a teacher that teaches kids instruments?
8 0
3 years ago
Read 2 more answers
Other questions:
  • Privacy concerns, financial information, security of your personal data has
    14·1 answer
  • We will pass in 2 values, X and Y. You should calculate XY XY and output only the final result. You will probably know that XY X
    13·1 answer
  • If a user wants to add an expansion card to increase the memory of a computer, where should the user insert the card?
    12·2 answers
  • ___________ is related to mass, but also includes the gravitational pull of the Earth.
    14·1 answer
  • (a) Define a goal for software product quality and an associated metric for that attribute. (b) Explain how you could show that
    7·1 answer
  • Write an expression whose value is the concatenation of the three strigs name1, name2, and name3, separated by commas
    9·1 answer
  • What type of error occurred??
    10·1 answer
  • NEXT
    15·2 answers
  • What are the best ways to conduct research for a presentation? Check all that apply.
    7·2 answers
  • Taking this driver education course
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!