Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
6_010. Completed
Browse files Browse the repository at this point in the history
  • Loading branch information
tueduong05 committed Oct 25, 2023
1 parent 2c075f9 commit 4bc3cc9
Showing 1 changed file with 56 additions and 18 deletions.
74 changes: 56 additions & 18 deletions Problem_006/6_010.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,63 @@
#include <iostream>
using namespace std;

void Nhap(int[], int&);
void Xuat(int[], int);
void NoiMang(int[], int, int[], int, int[], int);

int main()
{
// undone
float a[100], b[100], c[200];
int array_a, array_b;
cin >> array_a;
for (int i = 0; i < array_a; i++)
cin >> a[i];
cin >> array_b;
for (int i = 0; i < array_b; i++)
cin >> b[i];
int m = 0, n = 0;
int array_c = array_a + array_b;
for (int i = 0; i < array_c; i++)
if (a[m] < b[n] || n >= array_b)
c[i] = a[m++];
else
c[i] = b[n++];
for (int i = 0; i < array_c; i++)
cout << c[i] << " ";
int na, nb;
int a[100], b[100], c[200];
Nhap(a, na);
Nhap(b, nb);
NoiMang(a, na, b, nb, c, na + nb);
Xuat(c, na + nb);
return 0;
}

void NoiMang(int a[], int na, int b[], int nb, int c[], int n)
{
int i = 0, j = 0, k = 0;
while (i < na && j < nb)
{
if (a[i] <= b[j])
{
c[k] = a[i];
i++;
}
else
{
c[k] = b[j];
j++;
}
k++;
}

while (i < na)
{
c[k] = a[i];
i++;
k++;
}

while (j < nb)
{
c[k] = b[j];
j++;
k++;
}
}

void Nhap(int a[], int& n)
{
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
}

void Xuat(int a[], int n)
{
for (int i = 0; i < n; i++)
cout << a[i] << " ";
}

0 comments on commit 4bc3cc9

Please sign in to comment.