- #include <iostream>
- using namespace std;
- void sort(int x[], int n)
- {
- int temp;
- int i;
- int j;
- for (i = 1; i < n; ++i)
- {
- temp = x[i];
- for (j = i - 1; j >= 0; --j)
- {
- if (x[j] > temp)
- {
- x[j + 1] = x[j];
- }
- else
- {
- break;
- }
- }
- x[j + 1] = temp;
- }
- }
- int median(int x[], int y[], int n)
- {
- int first_x = 0;
- int first_y = 0;
- int last_x = n - 1;
- int last_y = n - 1;
- int count = 0;
- int mid_x;
- int mid_y;
- int z[4];
- while (last_x - first_x > 1 || last_y - first_y > 1)
- {
- mid_x = (first_x + last_x) / 2;
- mid_y = (first_y + last_y) / 2;
- if (x[mid_x] <= y[mid_y])
- {
- count += (mid_x - first_x);
- first_x = mid_x;
- last_y = mid_y;
- }
- else
- {
- count += (mid_y - first_y);
- first_y = mid_y;
- last_x = mid_x;
- }
- }
- int number;
- for (number = 0; first_x <= last_x; ++first_x)
- {
- z[number++] = x[first_x];
- }
- for (; first_y <= last_y; ++first_y)
- {
- z[number++] = y[first_y];
- }
- sort(z, number);
- return z[n - count - 1];
- }
- int main(int argc, char *argv[])
- {
- return 0;
- }