static void Main(string[] args)
 {
     Slownik<string, int> slowniczek = new Slownik<string,int>();
     slowniczek.dodawanieWartosci("andrzej", 32);
     slowniczek.dodawanieWartosci("zdzisław", 48);
     slowniczek.dodawanieWartosci("stanisław", 35);
     slowniczek.usuwanieKlucza("zdzisław");
     try
     {
         Console.WriteLine(slowniczek.wyszukiwanie("zdzisław"));
     }
     catch (ExceptionBrakKlucza)
     {
         Console.WriteLine("jajecznica");
     }
     try
     {
         Console.WriteLine(slowniczek.wyszukiwanie("stanisław"));
     }
     catch (ExceptionBrakKlucza)
     {
         Console.WriteLine("jajecznica");
     }
     Console.ReadLine();
 }
Example #2
0
    public static void Main()
    {
        Console.WriteLine("Testowanie Listy");
        Lista <int> L = new Lista <int> ();

        L.add("back", 1);
        L.add("front", 11);
        L.add("back", 3);
        L.add("front", 12);
        L.add("back", 123);
        foreach (int x in L)
        {
            Console.WriteLine("{0}", x);
        }
        Console.WriteLine(L);
        Console.WriteLine("dlugosc listy {0}", L.Length);
        Console.WriteLine("element nr 2: {0}", L[2]);
        L.remove("back");
        L.remove("front");
        foreach (int x in L)
        {
            Console.WriteLine("{0}", x);
        }
        Console.WriteLine("Testowanie Slownika");
        Slownik <string, string> D = new Slownik <string, string> ();

        D.add("a", "A");
        D.add("b", "B");
        Console.WriteLine(D.value("a"));
        Console.WriteLine(D.value("b"));
    }
Example #3
0
    public static void Main(string[] args)
    {
        Console.WriteLine("Hash Map: \n");
        Slownik <string, int> slownik = new Slownik <string, int>();

        Console.WriteLine("Adding 3 elements... ");
        slownik.create("first", 17);
        slownik.create("second", 2);
        slownik.create("third", 42);
        Console.WriteLine("Created structure: ");
        slownik.print();

        Console.WriteLine("------");
        Console.WriteLine("Size: ");
        Console.WriteLine(slownik.getSize());

        Console.WriteLine("Removing second element... ");
        Console.WriteLine(slownik.remove("second"));
        slownik.print();
        Console.WriteLine("------");
        Console.WriteLine("Get third's value: ");


        Console.WriteLine(slownik.get("third"));
        // Console.WriteLine(slownik.get("for"));
        Console.WriteLine("\nIs empty: ");
        Console.WriteLine(slownik.isEmpty());

        Console.WriteLine("Clearing hash table... ");
        Console.WriteLine(slownik.remove("third"));
        Console.WriteLine(slownik.remove("first"));
        slownik.print();
        Console.WriteLine("\nIs empty: ");
        Console.WriteLine(slownik.isEmpty());
    }
        static void Main(string[] args)
        {
            Lista <int>           l   = new Lista <int>();
            Slownik <string, int> slo = new Slownik <string, int>();

            string s = "sss";

            slo.add("ssss", 5);



            l.addFirst(1);
            l.addFirst(2);
            l.addFirst(3);
            l.addLast(4);
            l.addLast(4);
            l.addLast(4);
            l.addLast(4);
            l.addFirst(8);
            l.PrintList();
            Console.WriteLine("Hello World!");
            l.removeFirst();
            l.removeLast();
            l.PrintList();
        }
Example #5
0
File: Graf.cs Project: mtdudek/PO
 public Graf2()
 {
     S            = new Slownik <string, Vertix>();
     Si           = new Slownik <int, Vertix>();
     liczba_wierz = new int();
     liczba_wierz = 0;
 }
Example #6
0
    public static void Main()
    {
        Slownik <string, string> S = new Slownik <string, string>();

        while (true)
        {
            string op = Console.ReadLine();
            if (op == "add")
            {
                string key = Console.ReadLine();
                string val = Console.ReadLine();
                S.add(key, val);
                Console.WriteLine("dodalem");
            }
            else if (op == "remove")
            {
                string key = Console.ReadLine();
                S.remove(key);
                Console.WriteLine("usunalem");
            }
            else if (op == "value")
            {
                string key = Console.ReadLine();
                Console.WriteLine("key: {0} value : {1}", key, S.value(key));
            }
            else if (op == "end")
            {
                break;
            }
        }
    }
Example #7
0
File: Graf.cs Project: mtdudek/PO
 public Graf1()
 {
     liczba_wierz = new int();
     liczba_wierz = 0;
     actual_tab   = new int[liczba_wierz, liczba_wierz];
     act_kra      = new int[liczba_wierz];
     Sl1          = new Slownik <string, int>();
     Sl2          = new Slownik <int, string>();
 }
Example #8
0
        static void Main(string[] args)
        {
            Slownik <string, int> Sl = new Slownik <string, int>();

            Console.Write("Dostępne operacje:\n1 K V->dodaj element z kluczem K" +
                          " i wartością V;\n2 K->wynisuje element z kulczem K;\n3 K->usuwa" +
                          " element z kluczem K;\n4->wypisz zawartość słownika;\n" +
                          "5->zakończ program.\n");
            while (true)
            {
                Console.Write("Podaj polecenie>");
                string   h   = Console.ReadLine();
                string[] tab = h.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                int      p;
                if (!Int32.TryParse(tab[0], out p))
                {
                    Console.Write("Złe polecenie!!\n");
                    continue;
                }
                if (p == 1)
                {
                    if ((tab.Length == 3) && (Int32.TryParse(tab[2], out p)))
                    {
                        Sl.dodaj_element_z_kluczem(tab[1], p);
                    }
                    else
                    {
                        Console.Write("Złe dane!!\n");
                    }
                }
                else if (p == 2)
                {
                    Console.WriteLine(Sl.znajdz_element_z_kluczem(tab[1]));
                }
                else if (p == 3)
                {
                    Sl.usun_element_z_kluczem(tab[1]);
                }
                else if (p == 4)
                {
                    Sl.wypisz_caly_slownik();
                }
                else if (p == 5)
                {
                    break;
                }
                else
                {
                    Console.Write("Złe polecenie!!\n");
                }
            }
        }
Example #9
0
        //Dijkstra
        static void Dijkstra(string start, string koniec, graf_interface graf)
        {
            p.Reset_wie();
            p.Reset_kraw();
            kra k = new kra(0, "");
            Slownik <string, int> s   = new Slownik <string, int>();
            Slownik <int, string> i_s = new Slownik <int, string>();

            int[]  odleglosci = new int[w1];
            bool[] bylem      = new bool[w1];
            for (int i = 0; i < w1; i++)
            {
                odleglosci[i] = Int32.MaxValue;
                bylem[i]      = false;
                string h = p.Nastepny_wierzchołek();
                s.dodaj_element_z_kluczem(h, i);
                i_s.dodaj_element_z_kluczem(i, h);
            }
            odleglosci[s.znajdz_element_z_kluczem(start)] = 0;
            while (!bylem[s.znajdz_element_z_kluczem(koniec)])
            {
                int min = Int32.MaxValue, poz = -1;
                for (int i = 0; i < w1; i++)
                {
                    if (!bylem[i] && odleglosci[i] < min)
                    {
                        min = odleglosci[i];
                        poz = i;
                    }
                }
                if (poz == -1)
                {
                    break;
                }
                bool kon = true;
                bylem[poz] = true;
                while (kon)
                {
                    try { k = graf.Kolejna_krawędź(i_s.znajdz_element_z_kluczem(poz)); }
                    catch { kon = false; }
                    if (!kon)
                    {
                        break;
                    }
                    odleglosci[s.znajdz_element_z_kluczem(k.get_dest())] =
                        odleglosci[poz] + k.get_weigth();
                }
            }
            odleglosci = null;
            bylem      = null;
            s          = null;
        }
Example #10
0
    static void Main(string[] args)
    {
        Slownik <int, string> slownik = new Slownik <int, string>();

        slownik.Dodaj(1, "a");
        slownik.Dodaj(2, "b");
        slownik.Dodaj(3, "c");
        slownik.Dodaj(4, "d");
        slownik.Dodaj(5, "e");
        Console.WriteLine(slownik.Szukaj(4));
        Console.WriteLine(slownik.Szukaj(3));
        slownik.Usun(5);
        Console.WriteLine(slownik.Szukaj(5));
        Console.WriteLine(slownik.Szukaj(4));
    }
Example #11
0
File: Graf.cs Project: mtdudek/PO
 public Graf1(string[] k)
 {
     liczba_wierz = new int();
     liczba_wierz = k.Length;
     actual_tab   = new int[liczba_wierz, liczba_wierz];
     act_kra      = new int[liczba_wierz];
     Sl1          = new Slownik <string, int>();
     Sl2          = new Slownik <int, string>();
     for (int i = 0; i < k.Length; i++)
     {
         Sl1.dodaj_element_z_kluczem(k[i], i);
         Sl2.dodaj_element_z_kluczem(i, k[i]);
         act_kra[i] = -1;
     }
 }
Example #12
0
 public void Add(k key, v val)
 {
     if (key.CompareTo(this.key) == 0)
     {
         Console.WriteLine("nieprawidlowy klucz");
     }
     else
     {
         if (this.next != null)
         {
             this.next.Add(key, val);
         }
         else
         {
             this.next = new Slownik <k, v>(key, val);
         }
     }
 }
Example #13
0
    public static void Main(string[] args)
    {
        Slownik <int, string> nowy = new Slownik <int, string> ();

        nowy.Dodaj(2, "ala");
        nowy.Dodaj(2, "ala2");
        nowy.Wypisz();
        Console.WriteLine("Po usuniecie rekordu nr: 2");
        nowy.Usun(2);
        nowy.Wypisz();
        nowy.Dodaj(1, "maja");
        nowy.Dodaj(3, "kaja");
        nowy.Dodaj(4, "franka");
        nowy.Wypisz();
        if (nowy.Wyszukaj(4))
        {
            Console.WriteLine("Sukces");
        }
    }
Example #14
0
        static void Main(string[] args)
        {
            Slownik <int, int> dict = new Slownik <int, int>();

            dict.Add(1, 10);
            dict.Add(2, 11);
            dict.Add(3, 12);
            dict.Add(10, 13);
            dict.Add(4, 14);
            dict.Add(5, 15);
            dict.Add(6, 16);
            dict.Add(7, 17);
            dict.Add(8, 18);
            dict.Add(9, 19);
            dict.Add(11, 20);


            Console.WriteLine(dict.Search(4));
            dict.Delete(4);
            Console.WriteLine(dict.Search(4));
            Console.WriteLine(dict.Search(5));
        }
        static void Main(string[] args)
        {
            Slownik <string, int> s = new Slownik <string, int>();

            s.Add("po", 5);
            Console.WriteLine(s.Take("po"));
            s.Del("po");
            s.Add("Ala", 3);
            s.Add("ma", 1);
            s.Add("kota", 4);
            s.Add("psa", 415);
            Console.WriteLine(s.Take("Ala"));
            Console.WriteLine(s.Take("ma"));
            Console.WriteLine(s.Take("kota"));
            Console.WriteLine(s.Take("Ala"));
            Console.WriteLine(s.Take("ma"));
            Console.WriteLine(s.Take("psa"));
            s.Del("psa");
            Console.WriteLine(s.Take("Ala"));
            Console.WriteLine(s.Take("ma"));
            Console.WriteLine(s.Take("psa"));
        }
Example #16
0
 public void Del(k key)
 {
     if (key.CompareTo(this.next.key) == 0 && this.next.next == null)
     {
         this.next = null;
     }
     else
     {
         if (key.CompareTo(this.key) == 0)
         {
             if (this.next != null)
             {
                 this.key  = this.next.key;
                 this.val  = this.next.val;
                 this.next = this.next.next;
             }
         }
         if (this.next != null)
         {
             this.next.Del(key);
         }
     }
 }
Example #17
0
 public Slownik()
 {
     this.val  = default(v);
     this.key  = default(k);
     this.next = null;
 }
Example #18
0
 protected Slownik(k key, v val)
 {
     this.val  = val;
     this.key  = key;
     this.next = null;
 }
Example #19
0
File: Graf.cs Project: mtdudek/PO
        //Konstruktor
        public Graf_random_gen(int w, int k)
        {
            w_s         = w;
            k_s         = k;
            index1      = -1;
            index2      = -1;
            i_s         = new Slownik <int, string>();
            s           = new Slownik <int, Slownik <int, bool> >();
            wierzchołki = new string[w];
            if (k > w * (w - 1) / 2)
            {
                k = w * (w - 1) / 2;
            }
            krawedzie = new triple[k];
            //Generowanie wierzchołków
            for (int i = 0; i < w; i++)
            {
                string h = String_gen();
                wierzchołki[i] = h;
                i_s.dodaj_element_z_kluczem(i, h);
                s.dodaj_element_z_kluczem(i, new Slownik <int, bool>());
            }
            Console.WriteLine("Mam wierzchołki");
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    if (i == j)
                    {
                        s.znajdz_element_z_kluczem(i).
                        dodaj_element_z_kluczem(j, true);
                    }
                    else
                    {
                        s.znajdz_element_z_kluczem(i).
                        dodaj_element_z_kluczem(j, false);
                    }
                }
            }
            //Generowanie krawędzi
            Random rand1 = new Random(new System.DateTime().Millisecond);
            Random rand2 = new Random(new System.DateTime().Millisecond * 11);

            for (int i = 0; i < k; i++)
            {
                int a = rand1.Next(w);
                int b = rand2.Next(w);
                int c = rand1.Next(1, 10000);
                if (a == b)
                {
                    i--;
                }
                else if (s.znajdz_element_z_kluczem(a).
                         znajdz_element_z_kluczem(b))
                {
                    i--;
                }
                else
                {
                    s.znajdz_element_z_kluczem(a).zmien_wartosc(b, true);
                    s.znajdz_element_z_kluczem(b).zmien_wartosc(a, true);
                    krawedzie[i] = new triple(i_s.znajdz_element_z_kluczem(a),
                                              i_s.znajdz_element_z_kluczem(b), c);
                }
            }
        }