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
Ted is looking for a reliable source for his paper. Which of the following sites would be considered reliable?
Lubov Fominskaja [6]

Answer:

A site where the author's information and qualifications are listed

Explanation:

When conducting online research, it is recommended that you look for reliable sources that will provide concrete evidence based on credible results. Credibility, in most cases, will start with the authors of the articles. Look for articles written by renown and respected authors. Evaluate keenly and avoid Wikipedia authors who are mostly anonymous. Determine their expertise, and if you can, do an additional Google research on them and find out whether they are credible or not.

8 0
3 years ago
12.
natali 33 [55]

Answer:

The answer is "Its fundamental economic structure of IP, which is based on the concept of incentives".

Explanation:

In the given question the correct choice is missing so, its solution can be defined as follows:

It is a copyrighted category that includes subjective human mind works. which exists in different forms, and also some countries recognize much more than others. Copyright laws, patents, trade secrets, and trademarks are the most famous types.  

  • This is a law that promotes the creation of a broad range of intellectual goods.
  • To do just that, the law gives the information and creative goods made, generally for a limited time, rights to individuals and companies.
7 0
3 years ago
You have a network that occupies the top floor of a three-story building. The WAN service provider has installed the line for th
patriot [66]

Answer:

Demarc Extension.

Explanation:

In this scenario, you have a network that occupies the top floor of a three-story building. The wide area network (WAN) service provider has installed the line for the WAN service in a wiring closet on the main floor.

Hence, you would use the Demarc Extension to relocate the WAN line into a wiring closet on your floor.

A Demarc Extension refers to a cabling channel or transmission path which typically originates from the interface of an internet service provider known as demarcation point to the termination point present at the premises of the end users, usually far from the minimum point of entry (MPOE).

4 0
3 years ago
You put $500 in an interest bearing bank account that pays 2% per year but has a fee of $2 per month. Are you getting ahead?
MA_775_DIABLO [31]
The answer is b) No

2% of 500 is 10.
$10 interest per year.

There are 12 months in a year. $2 per month
2 * 12 = 24
$24 a year is the fee. 

So, if you have a $10 interest per year, but are paying $24 per year on a fee, you are not getting ahead. 


Hope this helps you! (:
-Hamilton1757
4 0
3 years ago
Read 2 more answers
Define the term algorithm and describe how programmers use algorithms when designing a program.
Ber [7]

Answer:

programming algorithm as a recipe that describes the exact steps needed for the computer to solve a problem or reach a goal. In many cases, there are multiple ways to perform a specific operation within a software program. Therefore, programmers usually seek to create the most efficient algorithms possible. By using highly efficient algorithms, developers can ensure their programs run as fast as possible and use minimal system resources. Of course, not all algorithms are created perfectly the first time. Therefore, developers often improve existing algorithms and include them in future software updates. When you see a new version of a software program that has been "optimized" or has "faster performance," it most means the new version includes more efficient algorithms.

Explanation:

3 0
3 years ago
Other questions:
  • What is the highest education degree available at a community college
    14·1 answer
  • How can you create the first row of the table as the header of the table
    15·2 answers
  • _____ are the most fundamental components of designing a training program that determine the amount of stress placed on the body
    6·1 answer
  • Which of the following is not a data in python. float, integer, bool, str.​
    14·1 answer
  • The Excel application is used to create
    7·1 answer
  • Java Eclipse homework. I need help coding this|
    10·1 answer
  • 20. Describe the steps that transform a program written in a high-level language such as C into a representation that is directl
    9·1 answer
  • Create the HTML code for this
    14·1 answer
  • How to tell if your cell phone is being tracked tapped or monitored by spy software?
    12·1 answer
  • When an AC voltage is being measured
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!