예제 #1
0
        public static int NumCollisions(HashTable HashT)
        {
            Auto elem;
            int  Num = 0;

            for (int i = 0; i < HashT.GetTable().Length; i++)
            {
                if (HashT.GetTable()[i] != null && HashT.GetTable()[i].Next != null)
                {
                    elem = HashT.GetTable()[i];
                    while (elem.Next != null)
                    {
                        Num++;
                        elem = elem.Next;
                    }
                }
            }
            return(Num);
        }
예제 #2
0
        public static void InfInTable(HashTable HashT, ref DataGridView dataGridView)
        {
            dataGridView.Rows.Clear();
            int  j;
            Auto elem;

            for (int i = 0; i < HashT.GetTable().Length; i++)
            {
                if (HashT.GetTable()[i] != null)
                {
                    j = 1;

                    dataGridView.Rows.Add(i /*хеш-адрес*/,
                                          j /*номер в цепочке*/,
                                          HashT.GetTable()[i].GetMark() /*марка*/,
                                          HashT.GetTable()[i].GetModel() /*модель*/,
                                          HashT.GetTable()[i].GetYear() /*год*/,
                                          HashT.GetTable()[i].GetCarcass() /*корпус*/);

                    if (HashT.GetTable()[i].Next != null)
                    {
                        elem = HashT.GetTable()[i].Next;
                        while (elem != null)
                        {
                            j++;
                            dataGridView.Rows.Add(i /*хеш-адрес*/,
                                                  j /*номер в цепочке*/,
                                                  elem.GetMark() /*марка*/,
                                                  elem.GetModel() /*модель*/,
                                                  elem.GetYear() /*год*/,
                                                  elem.GetCarcass() /*корпус*/);
                            elem = elem.Next;
                        }
                    }
                }
            }
        }
예제 #3
0
        private void SaveBatton_Click(object sender, EventArgs e)
        {
            bool         flag       = false;
            StreamWriter Fileoutput = null;
            HashTable    SaveTable  = null;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (saveFileDialog1.FileName == "")
                {
                    return;
                }
                try
                {
                    Fileoutput = new StreamWriter(saveFileDialog1.FileName, false, Encoding.Default);
                    while (flag == false)
                    {
                        if (FileOutCheckMulti.Checked == true)
                        {
                            SaveTable = Multiplication;
                            flag      = true;
                        }
                        if (FileOutCheckDivision.Checked == true)
                        {
                            SaveTable = Division;
                            flag      = true;
                        }
                        if (FileOutCheckMulti.Checked == false && FileOutCheckDivision.Checked == false)
                        {
                            MessageBox.Show(String.Format(ErrorBox), "Информация о таблице.");
                            flag = false;
                        }
                    }


                    for (int i = 0; i < (SaveTable.GetTable()).Length; i++)
                    {
                        if (SaveTable.GetTable()[i] != null)
                        {
                            SaveTable.GetTable()[i].Save(Fileoutput);

                            if (SaveTable.GetTable()[i].Next != null)
                            {
                                Auto elem = SaveTable.GetTable()[i].Next;
                                while (elem != null)
                                {
                                    elem.Save(Fileoutput);
                                    elem = elem.Next;
                                }
                            }
                        }
                    }
                    MessageBox.Show(String.Format(GoodFileIn), "Информация о файле");
                }
                catch
                {
                    MessageBox.Show(String.Format(ErrorFileIn), "Информация о файле");
                }
                finally
                {
                    Fileoutput.Close();
                }
            }
        }