Advertisement
dmkozyrev

compare

Jan 22nd, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void swap(double * a, double * b){
  4.     double temp = *a;
  5.     *a = *b;
  6.     *b = temp;
  7. }
  8.  
  9. void bubble_sort(double * a, int N){
  10.     int i, j;
  11.     for (i = 0; i < N-1; i++)
  12.         for (j = i+1; j < N; j++)
  13.             if (a[i] > a[j])
  14.                 swap(&a[i], &a[j]);
  15. }
  16.  
  17. int compare(double * a, double * b, int N, int M){
  18.     bubble_sort(a, N);
  19.     bubble_sort(b, M);
  20.     if (a[N-1] < b[0])
  21.         return -1;
  22.     else if (a[0] > b[M-1])
  23.         return 1;
  24.     else
  25.         return 0;
  26. }
  27.  
  28. void fill_mas(double * mas, int N, int a, int b){
  29.     int i;
  30.     for(i = 0; i < N; i++)
  31.         mas[i] = rand()%(b-a+1)+a;
  32. }
  33.  
  34. void print_mas(double * a, int N){
  35.     int i;
  36.     for(i = 0; i < N; i++)
  37.         printf("%f ", a[i]);
  38.     printf("\n");
  39. }
  40.  
  41. int main(){
  42.     unsigned const int N = 5;
  43.     unsigned const int M = 3;
  44.     double a[N], b[M];
  45.    
  46.     fill_mas(a, N, -10, 0);
  47.     fill_mas(b, M, 1, 10);
  48.    
  49.     print_mas(a, N);
  50.     print_mas(b, M);
  51.    
  52.     int res = compare(a, b, N, M);
  53.     printf("res = %d", res);
  54.    
  55.     return 0;  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement