Zadanie zo skúšky PAZ1b (knihovník)
Created: 2008-06-19 - 17:10
Moje riesenia v O(n*n) (to je tak na C-cko):
public class Skuska1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int[] pole = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; spoj(pole); for (int i = 0; i < pole.length; i++) { System.out.println(pole[i]); } } public static void spoj(int[] pole) { int poc = 0; for (int i = 0; i < pole.length - poc; i++) { int pom3 = 0; int m = i + poc + pole.length / 2; try { pom3 = pole[m]; } catch (Exception e) { break; } posun(i, i + pole.length / 2 + poc, pole, pom3); i++; poc--; } } public static void posun(int od, int po, int[] pole, int nahradeny) { int i = od; int pom = pole[od]; while (od < pole.length - 1) { int pom2 = pole[od + 1]; pole[od + 1] = pom; pom = pom2; od++; } pole[i + 1] = nahradeny; po++; while (po < pole.length - 1) { pole[po] = pole[po + 1]; po++; } if (po < pole.length) pole[po] = pom; } }