예제 #1
0
        } // koniec przycisku

        private void LancuchIntPrzycisk_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int a = int.Parse(lancuchowa.Text);

                if (a < 0)
                {
                    MessageBox.Show("Nie ujemne");
                    return;
                }
            }
            catch
            {
                MessageBox.Show("Nie litery i nie puste");
                return;
            }



            int hash_f(int s)
            {
                int uh, ip;

                uh = 0;
                for (ip = 0; ip < s.ToString().Length; ip++)
                {
                    uh = 2 * uh + 1 - (s.ToString()[ip] & 1);
                }
                return(uh % 10);
            }

            var timer = System.Diagnostics.Stopwatch.StartNew(); //licznik czasu
            List <DataClass> nrSeriiSzukanie = new List <DataClass>();
            int i, j, h, c, p = -1;
            var temp = new DataClass();

            for (i = 0; i < dataClass.Count(); i++)
            {
                nrSeriiSzukanie.Add(temp);
            }
            for (i = 0; i < dataClass.Count(); i++)
            {
                h = hash_f(dataClass[i].nrSerii);
                j = h;
                while (true)
                {
                    if (nrSeriiSzukanie[j].nrSerii == 0)
                    {
                        nrSeriiSzukanie[j] = dataClass[i];
                        break;
                    }
                    if (nrSeriiSzukanie[j].nrSerii == dataClass[i].nrSerii)
                    {
                        break;
                    }
                    j = (j + 1) % dataClass.Count();
                    if (j == h)
                    {
                        break;
                    }
                }
            }
            List <DataClass> tem = new List <DataClass>();

            for (i = 0; i < dataClass.Count(); i++)
            {
                h = hash_f(int.Parse(intPoleLancuch.Text));
                c = 0;
                j = h;
                p = -1;
                while (true)
                {
                    if (nrSeriiSzukanie[j].nrSerii == 0)
                    {
                        break;
                    }
                    if (nrSeriiSzukanie[j].nrSerii == int.Parse(intPoleLancuch.Text))
                    {
                        p = j;

                        break;
                    }
                    ;
                    j = (j + 1) % dataClass.Count();
                    if (j == h)
                    {
                        break;
                    }
                    c++;
                }
            }
            tem.Add(nrSeriiSzukanie[p]);
            timer.Stop();
            MessageBox.Show("Czas szukania binarnego to mili -> " + timer.ElapsedMilliseconds + "\nIlość ticków -> " + timer.ElapsedTicks
                            + "\nCzas w nanosekundach -> " + timer.ElapsedTicks * 1000000000 / System.Diagnostics.Stopwatch.Frequency
                            ); //czas wykonywania -> komunikat

            Tabela.ItemsSource = null;
            Tabela.ItemsSource = tem;
            Tabela.DataContext = tem;
        }
예제 #2
0
        private void LancuchPrzycisk_Click(object sender, RoutedEventArgs e)
        {
            int hash_f(string s)
            {
                int uh, ip;

                uh = 0;
                for (ip = 0; ip < s.Length; ip++)
                {
                    uh = 2 * uh + 1 - (s[ip] & 1);
                }
                return(uh % 10);
            }

            var timer = System.Diagnostics.Stopwatch.StartNew(); //licznik czasu
            List <DataClass> brandSzukanie = new List <DataClass>();
            int i, j, h, c, p = -1;
            var temp = new DataClass();

            for (i = 0; i < dataClass.Count(); i++)
            {
                brandSzukanie.Add(temp);
            }
            for (i = 0; i < dataClass.Count(); i++)
            {
                h = hash_f(dataClass[i].brand);
                j = h;
                while (true)
                {
                    if (brandSzukanie[j].brand == null)
                    {
                        brandSzukanie[j] = dataClass[i];
                        break;
                    }
                    if (brandSzukanie[j].brand == dataClass[i].brand)
                    {
                        break;
                    }
                    j = (j + 1) % dataClass.Count();
                    if (j == h)
                    {
                        break;
                    }
                }
            }
            List <DataClass> tem = new List <DataClass>();

            for (i = 0; i < dataClass.Count(); i++)
            {
                h = hash_f(lancuchowa.Text);
                c = 0;
                j = h;
                p = -1;
                while (true)
                {
                    if (brandSzukanie[j].brand == null)
                    {
                        break;
                    }
                    if (brandSzukanie[j].brand == lancuchowa.Text)
                    {
                        p = j;

                        break;
                    }
                    ;
                    j = (j + 1) % dataClass.Count();
                    if (j == h)
                    {
                        break;
                    }
                    c++;
                }
            }
            tem.Add(brandSzukanie[p]);
            timer.Stop();
            MessageBox.Show("Czas szukania binarnego to mili -> " + timer.ElapsedMilliseconds + "\nIlość ticków -> " + timer.ElapsedTicks
                            + "\nCzas w nanosekundach -> " + timer.ElapsedTicks * 1000000000 / System.Diagnostics.Stopwatch.Frequency
                            ); //czas wykonywania -> komunikat

            Tabela.ItemsSource = null;
            Tabela.ItemsSource = tem;
            Tabela.DataContext = tem;
        } // koniec przycisku