public Zbior[] Podzbiory() { Zbior[] podzbiory = new Zbior[(int)Math.Pow(2, this.Ile)]; int i = 0; Zbior.PodzbioryRek(this, new Zbior(), podzbiory, ref i); //return Zbior.getSubsets(this); return(podzbiory); }
private static void PodzbioryRek(Zbior z1, Zbior z2, Zbior[] tab, ref int i) { for (int j = 0; j < 63; j++) { if (z1[j]) { z1[j] = false; z2[j] = true; tab[i++] = z2; Zbior.PodzbioryRek(z1, z2, tab, ref i); z2[j] = false; } } }
private static Zbior[] getSubsets(Zbior zb) { Zbior[] subsets = new Zbior[(int)Math.Pow(2, zb.Ile)]; subsets[0] = zb; int nextFree = 1; for (int i = 0; i < 63; i++) { if (zb[i]) { zb[i] = true; Zbior[] sub1 = Zbior.getSubsets(zb); for (int j = 0; j < sub1.Length; j++) { subsets[nextFree++] = sub1[j]; } zb[i] = false; } } return(subsets); }
public Zbior(Zbior zb) { this.zbior = zb.zbior; }