Exemple #1
0
        public static int NumberOfRuns(string BinaryString, out BindingList <Runs> runsList)
        {
            runsList = new BindingList <Runs>();
            List <int> runLens = new List <int>();

            string str = BinaryString;

            int  strlen = str.Length, numberOfRuns = 1, internalSayac = 1;
            char ilk = str[0];

            for (int i = 1; i < strlen; i++)
            {
                if (str[i] == ilk)
                {
                    internalSayac++;
                    continue;
                }
                else
                {
                    //Debug.WriteLine(internalSayac);
                    runLens.Add(internalSayac);
                    internalSayac = 1;
                    ilk           = str[i];
                    numberOfRuns++;
                }
            }

            //Debug.WriteLine(internalSayac);
            runLens.Add(internalSayac);

            runLens.Sort();

            foreach (int run in runLens)
            {
                bool yoksa = true;
                foreach (Runs r in runsList)
                {
                    if (r.RunLength == run)
                    {
                        r.Count++;
                        yoksa = false;
                        break;
                    }
                }
                if (yoksa)
                {
                    Runs r = new Runs(run, 1);
                    runsList.Add(r);
                }
            }

            return(numberOfRuns);
        }
Exemple #2
0
        public static int NumberOfRuns(string BinaryString, out BindingList<Runs> runsList)
        {
            runsList = new BindingList<Runs>();
            List<int> runLens = new List<int>();

            string str = BinaryString;

            int strlen = str.Length, numberOfRuns = 1, internalSayac = 1;
            char ilk = str[0];
            for (int i = 1; i < strlen; i++)
            {
                if (str[i] == ilk)
                {
                    internalSayac++;
                    continue;
                }
                else
                {
                    //Debug.WriteLine(internalSayac);
                    runLens.Add(internalSayac);
                    internalSayac = 1;
                    ilk = str[i];
                    numberOfRuns++;
                }
            }

            //Debug.WriteLine(internalSayac);
            runLens.Add(internalSayac);

            runLens.Sort();

            foreach (int run in runLens)
            {
                bool yoksa = true;
                foreach (Runs r in runsList)
                {
                    if (r.RunLength == run)
                    {
                        r.Count++;
                        yoksa = false;
                        break;
                    }
                }
                if (yoksa)
                {
                    Runs r = new Runs(run, 1);
                    runsList.Add(r);
                }
            }

            return numberOfRuns;
        }