Exemple #1
0
    public static Zbiór CzęśćWspólnaZbiorów(Zbiór z1, Zbiór z2)
    {
        Zbiór wynik = new Zbiór();

        foreach (DictionaryEntry item in z1.elementy)
        {
            if (z2.CzyZawiera(item.Key))
            {
                wynik.Dodaj(item.Value);
            }
        }

        return(wynik);
    }
Exemple #2
0
    public static void Main(string[] args)
    {
        Zbiór set1 = new Zbiór();
        Zbiór set2 = new Zbiór();

        set1.Dodaj("1");
        set1.Dodaj("3");
        set1.Dodaj("4");
        set1.Dodaj("5");
        set1.Dodaj("7");

        set2.Dodaj("2");
        set2.Dodaj("3");
        set2.Dodaj("4");
        set2.Dodaj("5");
        set2.Dodaj("6");

        Zbiór częścWspolna = Zbiór.CzęśćWspólnaZbiorów(set1, set2);
        Zbiór suma         = Zbiór.SumaZbiorów(set1, set2);

        Console.WriteLine("Czesc wspolna:");

        foreach (DictionaryEntry item in częścWspolna.elementy)
        {
            Console.WriteLine("wartosc: {0}", item.Value);
        }

        Console.WriteLine("Suma:");

        foreach (DictionaryEntry item in suma.elementy)
        {
            Console.WriteLine("wartosc: {0}", item.Value);
        }

        Console.ReadKey();
    }