예제 #1
0
        public void CreateKareOrtasi(List <string> file)//Kare Ortası Fonksiyonu
        {
            int    arrayIndex     = 0;
            int    substringValue = arrayLength(file.Count);
            int    arraySize      = Convert.ToInt32(Math.Pow(10.0, Convert.ToDouble(substringValue)));
            string midSquareValue = "";
            long   fileValue      = 0;
            int    firstIndex     = 0;
            int    fileSize       = file.Count;

            string[] kareOrtasiArray = new string[arraySize];
            string[] sep;
            if (TextBoxAyirmaDegeri.Text != "")
            {
                sep = new string[] { TextBoxAyirmaDegeri.ToString() };
            }
            else
            {
                sep = new string[] { " " };
            }

            for (int i = 0; i < file.Count; i++)
            {
                string[] lines = file[i].Split(sep, StringSplitOptions.RemoveEmptyEntries);
                fileValue = long.Parse(lines[0].ToString());
                BigInteger x    = fileValue * fileValue;
                string     temp = x.ToString();
                midSquareValue = x.ToString().Substring(temp.Length - substringValue - 6, substringValue);
                arrayIndex     = Int32.Parse(midSquareValue);
                firstIndex     = arrayIndex;
                if (kareOrtasiArray[arrayIndex] == null)
                {
                    kareOrtasiArray[arrayIndex] = lines[0] + " " + lines[1];
                }
                else //lineer search
                {
                    fileSize = arraySize;
                    for (int j = arrayIndex; j < fileSize; j++)
                    {
                        arrayIndex = arrayIndex + 1;
                        if (arrayIndex < arraySize)
                        {
                            if (arrayIndex != firstIndex)
                            {
                                if (kareOrtasiArray[arrayIndex] == null)
                                {
                                    kareOrtasiArray[arrayIndex] = lines[0] + " " + lines[1];
                                    break;
                                }
                            }
                            else
                            {
                                LabelCreateResult2.Text += "!!!Kare Ortası Dizisi Dolu. ";
                            }
                        }
                        else
                        {
                            j          = -1;
                            arrayIndex = -1;
                            fileSize   = firstIndex;
                        }
                    }
                }
            }

            ExportTxt(kareOrtasiArray, "kareOrtasi");
        }
예제 #2
0
        //3-Arama ve Sürelerin Hesabı
        #region
        //3-Öğrenci numarası bulma sürelerini hesaplama fonksiyonu
        public Stopwatch calculateSearchTime(List <string> fileGelen, string ogrNumber, int choosen)
        {
            Stopwatch watch = new Stopwatch();

            switch (choosen)
            {
            case 1:     //Lineer Hesaplama
                int      found = 0;
                string[] sepLineer;
                if (TextBoxAyirmaDegeri.Text != "")
                {
                    sepLineer = new string[] { TextBoxAyirmaDegeri.ToString() };
                }
                else
                {
                    sepLineer = new string[] { " " };
                }
                watch = Stopwatch.StartNew();
                for (int i = 0; i < fileGelen.Count; i++)
                {
                    string[] linesLineer = fileGelen[i].Split(sepLineer, StringSplitOptions.RemoveEmptyEntries);
                    if (linesLineer[0].ToString() == ogrNumber)
                    {
                        found = i + 1;
                        break;
                    }
                }
                watch.Stop();
                LabelLineer.Text = "*Lineer arama sonucunda " + ogrNumber + " nolu öğrenci " + found + ". sırada ";
                break;

            case 2:     //Bolen-Kalan Hesaplama
                int      fileSizeBolen   = fileGelen.Count;
                int      arrayIndexBolen = Int32.Parse(ogrNumber) % fileSizeBolen;
                int      modValue        = fileGelen.Count;
                int      firstIndexBolen = arrayIndexBolen;
                string[] sepBolen;
                if (TextBoxAyirmaDegeri.Text != "")
                {
                    sepBolen = new string[] { TextBoxAyirmaDegeri.ToString() };
                }
                else
                {
                    sepBolen = new string[] { " " };
                }
                /*timer Start*/
                watch = Stopwatch.StartNew();
                string[] lines = fileGelen[arrayIndexBolen].Split(sepBolen, StringSplitOptions.RemoveEmptyEntries);
                if (lines[0] == null)
                {
                    LabelBolenKalan.Text = "Bölen Kalan-İlk İndex Noktasında Kayıt Yok!";
                    break;
                }
                else if (lines[0].ToString() == ogrNumber)
                {
                    LabelBolenKalan.Text = "*Bölen Kalan arama sonucunda " + ogrNumber + " nolu öğrenci " + (arrayIndexBolen + 1) + ". sırada ";
                    break;
                }
                else
                {
                    fileSizeBolen = fileGelen.Count;
                    for (int j = arrayIndexBolen + 1; j < fileSizeBolen; j++)
                    {
                        arrayIndexBolen = arrayIndexBolen + 1;
                        if (arrayIndexBolen < fileGelen.Count)
                        {
                            if (arrayIndexBolen != firstIndexBolen)
                            {
                                string[] lines2 = fileGelen[j].Split(sepBolen, StringSplitOptions.RemoveEmptyEntries);
                                if (lines2[0].ToString() == ogrNumber)
                                {
                                    LabelBolenKalan.Text = "*Bölen Kalan arama sonucunda " + ogrNumber + " nolu öğrenci " + (j + 1) + ". sırada ";
                                    break;
                                }
                            }
                            else
                            {
                                LabelBolenKalan.Text = "Bölen Kalan-Lineer Arama Sonucu: Kayıt Yok!";
                                break;
                            }
                        }
                        else
                        {
                            j = -1;
                            arrayIndexBolen = -1;
                            fileSizeBolen   = firstIndexBolen;
                        }
                    }
                }
                watch.Stop();
                break;

            case 3:     //Kare Ortası Hesaplama
                int        arrayIndexKare = 0;
                int        substringValue = arrayLength(fileGelen.Count);
                string     midSquareValue = "";
                long       fileValue      = long.Parse(ogrNumber);
                BigInteger x    = fileValue * fileValue;
                string     temp = x.ToString();
                midSquareValue = x.ToString().Substring(temp.Length - substringValue - 6, substringValue);
                arrayIndexKare = Int32.Parse(midSquareValue);

                int firstIndexKare = arrayIndexKare;
                int fileSize       = fileGelen.Count;

                string[] sepKare;
                if (TextBoxAyirmaDegeri.Text != "")
                {
                    sepKare = new string[] { TextBoxAyirmaDegeri.ToString() };
                }
                else
                {
                    sepKare = new string[] { " " };
                }
                /*timer Start*/
                watch = Stopwatch.StartNew();
                string[] linesKare = fileGelen[arrayIndexKare].Split(sepKare, StringSplitOptions.RemoveEmptyEntries);
                if (linesKare[0] == null)
                {
                    LabelKareOrtasi.Text = "Kare Ortası-İlk İndex Noktasında Kayıt Yok!";
                    break;
                }
                else if (linesKare[0].ToString() == ogrNumber)
                {
                    LabelKareOrtasi.Text = "*Kare Ortası arama sonucunda " + ogrNumber + " nolu öğrenci " + (arrayIndexKare + 1) + ". sırada ";
                    break;
                }
                else
                {
                    fileSize = fileGelen.Count;
                    for (int j = arrayIndexKare + 1; j < fileSize; j++)
                    {
                        arrayIndexKare = arrayIndexKare + 1;
                        if (arrayIndexKare < fileGelen.Count)
                        {
                            if (arrayIndexKare != firstIndexKare)
                            {
                                string[] lines4 = fileGelen[j].Split(sepKare, StringSplitOptions.RemoveEmptyEntries);
                                if (lines4[0].ToString() == ogrNumber)
                                {
                                    LabelKareOrtasi.Text = "*Kare Ortası arama sonucunda " + ogrNumber + " nolu öğrenci " + (j + 1) + ". sırada ";
                                    break;
                                }
                            }
                            else
                            {
                                LabelKareOrtasi.Text = "Kare Ortası-Lineer Arama Sonucu: Kayıt Yok!";
                                break;
                            }
                        }
                        else
                        {
                            j = -1;
                            arrayIndexKare = -1;
                            fileSize       = firstIndexKare;
                        }
                    }
                }
                watch.Stop();
                break;

            default: break;
            }

            return(watch);
        }
예제 #3
0
        //2-Bolen Kalan ve Kare Ortası Dosyalarının Oluşturulması
        #region
        public void CreateBolenKalan(List <string> file) //Bolen Kalan Fonksiyonu
        {
            int  arrayIndex = 0;
            int  modValue   = file.Count;
            long fileValue  = 0; //Lineer dosyadan okunan her bir satırdaki öğrenci num. tutan değişken
            int  firstIndex = 0; //Mod alındıktan sonra bulunan ilk değer
            int  fileSize   = file.Count;

            string[] bolenKalanArray = new string[file.Count];
            string[] sep;
            if (TextBoxAyirmaDegeri.Text != "")
            {
                sep = new string[] { TextBoxAyirmaDegeri.ToString() };
            }
            else
            {
                sep = new string[] { " " };
            }

            for (int i = 0; i < file.Count; i++)
            {
                string[] lines = file[i].Split(sep, StringSplitOptions.RemoveEmptyEntries);
                fileValue  = long.Parse(lines[0].ToString());
                arrayIndex = (int)(fileValue % modValue);
                firstIndex = arrayIndex;
                if (bolenKalanArray[arrayIndex] == null)
                {
                    bolenKalanArray[arrayIndex] = lines[0] + " " + lines[1];
                }
                else //lineer search
                {
                    fileSize = file.Count;
                    for (int j = arrayIndex; j < fileSize; j++)
                    {
                        arrayIndex = arrayIndex + 1;
                        if (arrayIndex < file.Count)      //Dosyanın sonuna kadar taranıp taranmadığının kontrolü
                        {
                            if (arrayIndex != firstIndex) //Dizinin tekrar en başından başladıktan sonra ilk index'e gelip gelmediğinin kontrolü
                            {
                                if (bolenKalanArray[arrayIndex] == null)
                                {
                                    bolenKalanArray[arrayIndex] = lines[0] + " " + lines[1];
                                    break;
                                }
                            }
                            else
                            {
                                LabelCreateResult2.Text += "!!!Bolen Kalan Dizisi Dolu. ";
                            }
                        }
                        else
                        {
                            j          = -1;
                            arrayIndex = -1;
                            fileSize   = firstIndex;
                        }
                    }
                }
            }
            ExportTxt(bolenKalanArray, "BolenKalan");
        }