Facebook
From Sole Peafowl, 3 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 229
  1. public class Main {
  2.     public static void main(String[] args) {
  3.         int[] num1 = {1, 5};
  4.         int[] num2 = {3, 4};
  5.         int dl = num1.length + num2.length;
  6.         int[] num3 = new int[dl];
  7.         int pos = 0;
  8.         for (int i : num1) {
  9.             num3[pos] = i;
  10.             pos++;
  11.         }
  12.         for (int j : num2) {
  13.             num3[pos] = j;
  14.             pos++;
  15.         }
  16.         quicksort(num3, 0, dl-1);
  17.         /*int srodkowy=0, mediana=0;
  18.         for(int k: num3){
  19.             if(num3.length%2==0){
  20.                 srodkowy=num3[(num3.length/2)];
  21.                 mediana=(srodkowy+(num3[(num3.length/2)+1]))/2;
  22.             }else{
  23.                 srodkowy=num3[(num3.length/2)+1];
  24.                 mediana=srodkowy;
  25.             }
  26.         }System.out.println(mediana); */
  27.         System.out.println(Arrays.toString(num3));
  28.     }
  29.  
  30.  
  31.     public static void quicksort(int[] tab, int l, int r) {
  32.         int srodek = tab[(l + r) / 2];
  33.         int p, q, x;
  34.         p = l;
  35.         q = r;
  36.         do {
  37.             while (tab[p] < srodek) p++;
  38.             while (tab[q] > srodek) q++;
  39.             if (p <= q) {
  40.                 x = tab[p];
  41.                 tab[p] = tab[q];
  42.                 tab[q] = x;
  43.                 p++;
  44.                 q--;
  45.             }
  46.         } while (p <= q);
  47.         if (q > l) quicksort(tab, l, q);
  48.         if (p < r) quicksort(tab, p, r);
  49.     }
  50. }