1035 insertion and merging (25 points)

According to Wikipedia:

Insertion sorting is an iterative algorithm, which obtains the input data one by one and produces the ordered output sequence step by step. In each iteration, the algorithm takes an element from the input sequence and inserts it into the correct position in the ordered sequence. Iterate until all elements are in order.

The merging and sorting operations are as follows: first, the original sequence is regarded as N ordered subsequences with only one element, and then two adjacent ordered subsequences are merged in each iteration until only one ordered sequence is left.

Now, given the original sequence and the intermediate sequence generated by a sorting algorithm, what sort algorithm is this algorithm?

### Input format:

Input the positive integer n (< 100) in the first row, then the N integers of the original sequence and the intermediate sequence generated by a sorting algorithm in the last row. It is assumed that the target sequence of sorting is ascending. Numbers are separated by spaces.

### Output format:

In the first row, insert sort is output to indicate Insertion Sort, or Merge Sort to indicate Merge Sort, and then in the second row, the result sequence of another round of iteration with this sort algorithm is output. The questions ensure that the results of each group of tests are unique. Numbers are separated by spaces, and there must be no extra spaces at the beginning and end of the line.

### Enter example 1:

```10
3 1 2 8 7 5 9 4 6 0
1 2 3 7 8 5 9 4 6 0
```

### Output example 1:

```Insertion Sort
1 2 3 5 7 8 9 4 6 0
```

### Enter example 2:

```10
3 1 2 8 7 5 9 4 0 6
1 3 2 8 5 7 4 9 0 6
```

### Output example 2:

```Merge Sort
1 2 3 8 4 5 7 9 0 6```

Hold it for several days!!!!

Not familiar with merging and sorting

```#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
void print(vector<int> v)
{
cout << v;
for (int i = 1; i < v.size(); i++)
{
cout << " " << v[i];
}
cout << endl;
}
void InsertionSort(vector<int> &v, vector<int> &s)
{
int temp;
int flag = 0;
int length = v.size();
for (int i = 1; i < length; i++)//length-1 sorting
{
for (int j = 0; j < i; j++)//insert
{
if (v[i] < v[j])
{
temp = v[i];
v.erase(v.begin() + i);//Delete v[i]
v.insert(v.begin() + j, temp);//Before v[i] is inserted into v[j]
break;
}
}
if (flag == 1)
{
cout << "Insertion Sort" << endl;
print(v);
break;
}
if (v == s)
flag = 1;
//print(v);
}
}

//Merge two ordered arrays
//You can't use the new vector push, so you can't change the original & there's no point
void merge(vector<int> &a, int l1, int l2, int l3, int l4)
{
vector<int> temp=a;
int i = l1;
int j = l3;
int count = l1;
while (i <= l2 && j <= l4)
{
if (temp[i] < temp[j])
{
a[count++]=temp[i];
i++;
}
else
{
a[count++] = temp[j];
j++;
}
}
while (i <= l2)
{
a[count++] = temp[i];
i++;
}
while (j <= l4)
{
a[count++] = temp[j];
j++;
}

}

void MergeSort(vector<int> &v,vector<int> &s)
{
int step = 2;
int flag = 0;
int n = v.size();
int mid;
for (step = 2; step / 2 < n; step = step * 2)
{
for (int i = 0; i<n; i += step)
{
mid = i + step / 2 - 1;
if (mid + 1 < n)
merge(v, i, mid, mid + 1, min(mid +step/2, n - 1));
//merge(nums, i, mid, mid + 1, min(i + step - 1, n-1));
//merge(v,i,mid,mid+1,mid+step/2);
}
if (flag == 1)
{
cout << "Merge Sort" << endl;
print(v);
return;
}

if (v == s)
{
flag = 1;
}
}
}

int main()
{
int n;
vector<int> v;
vector<int> s;
int temp;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> temp;
v.push_back(temp);
}
for (int i = 0; i < n; i++)
{
cin >> temp;
s.push_back(temp);
}
vector<int> a = v;
InsertionSort(v, s);
v = a;
MergeSort(v, s);
system("pause");
return 0;
}```