Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <pthread.h>
- #include <time.h>
- #include <stdlib.h>
- #define SWAP(A,B) {(A)=(A)^(B); (B)=(A)^(B); (A)=(A)^(B);}
- int getLen(FILE *in) {
- int size;
- fscanf(in, "%d", &size);
- return size;
- }
- void arrayFill(FILE *in, int array[], int limit) {
- int i = 0;
- for ( i ; i < limit && fscanf(in, "%d", &array[i]) > 0; i++ );
- }
- void arrayPrint(FILE *out, int array[], int size) {
- size = size - 1;
- int i = 0;
- for ( i; i < size; i++ ) {
- fprintf(out, "%d ", array[i]);
- }
- fprintf(out, "%d\n", array[size]);
- }
- void arraySort(int mas[], int n)
- {
- int last = n-1, left = 1, right = n-1, j;
- do
- {
- for(j = right; j >= left; j--)
- {
- if(mas[j-1] > mas[j])
- {
- SWAP(mas[j-1], mas[j]);
- last = j;
- }
- }
- left = last + 1;
- for(j = left; j <= right; j++)
- {
- if(mas[j-1] > mas[j])
- {
- SWAP(mas[j-1], mas[j]);
- last = j;
- }
- }
- right = last-1;
- } while(left < right);
- }
- int main() {
- FILE *in = fopen("task.in", "r");
- FILE *out = fopen("task.out", "w");
- int len1 = getLen(in);
- int len2 = getLen(in);
- int size = len1 + len2;
- int array1[len1], array2[len2], dst[size];
- int indexPosition;
- arrayFill(in, array1, len1);
- arrayFill(in, array2, len2);
- fclose(in);
- int i = 0;
- for ( i; i < len1; i++ ) {
- dst[i] = array1[i];
- }
- i = 0;
- for (i; i < len2; i++ ) {
- indexPosition = len1 + i;
- dst[indexPosition] = array2[i];
- }
- A:arraySort(array1, len1);
- B:arraySort(array2, len2);
- short count;
- for (count=0; count < 1; count++) {
- pid_t pid = fork();
- if (pid == 0)
- {
- if (count == 0)
- {
- goto A;
- }
- if (count == 1)
- {
- goto B;
- }
- }
- }
- arraySort(dst, size);
- arrayPrint(out, dst, size);
- fclose(out);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement