-
Notifications
You must be signed in to change notification settings - Fork 0
/
frame.c
61 lines (49 loc) · 1.12 KB
/
frame.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<stdio.h>
int main() {
int arr1[5000], arr2[3000], res[7000];
int i, j, k, packets, frames;
printf("\nThe number of packets count as array listing :");
scanf("%d", &packets);
for (i = 0; i < packets; i++) {
scanf("%d", &arr1[i]);
}
printf("\nThe number of frames count as array listing :");
scanf("%d", &frames);
for (i = 0; i < frames; i++) {
scanf("%d", &arr2[i]);
}
i = 0;
j = 0;
k = 0;
// Merging starts
while (i < packets && j < frames) {
if (arr1[i] <= arr2[j]) {
res[k] = arr1[i];
i++;
k++;
} else {
res[k] = arr2[j];
k++;
j++;
}
}
/* Some elements in array 'arr1' are still remaining
where as the array 'arr2' is exhausted */
while (i < packets) {
res[k] = arr1[i];
i++;
k++;
}
/* Some elements in array 'arr2' are still remaining
where as the array 'arr1' is exhausted */
while (j < frames) {
res[k] = arr2[j];
k++;
j++;
}
//Displaying elements of array 'res'
printf("\n packets and frames encapsulated as :");
for (i = 0; i < packets + frames; i++)
printf("%d ", res[i]);
return 0;
}