This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c075f9
commit 4bc3cc9
Showing
1 changed file
with
56 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] << " "; | ||
} |