Beispiel #1
0
        public string Sort(string Text)
        {
            int lenght = Text.Length;

            char[]      letters     = Text.ToCharArray();
            List <char> ListLetters = new List <char>();
            bool        isNotNull;
            string      nullStrng = msg1.nullStr;
            int         a         = 0;

            for (int i = 0; i < lenght; i++)
            {
                if (letters[i] >= 'а' && letters[i] <= 'я')
                {
                    ListLetters.Add(letters[i]);
                    a++;
                }
            }
            char[] newLetters = ListLetters.ToArray();
            int    l          = (new string(newLetters)).Length;
            int    count      = l;
            bool   swaped;

            do
            {
                swaped = false;
                for (int i = 1; i <= count - 1; i++)
                {
                    if (newLetters[i] < newLetters[i - 1])
                    {
                        char temp = newLetters[i];
                        newLetters[i]     = newLetters[i - 1];
                        newLetters[i - 1] = temp;
                        swaped            = true;
                    }
                }
                count--;
            } while(swaped);
            string newStr = string.Join("", newLetters);

            isNotNull = test2.TestNullStr(newStr);
            if (isNotNull == true)
            {
                return(newStr);
            }
            else
            {
                return(nullStrng);
            }
        }
Beispiel #2
0
        /*
         *  Метод Main выполняет вывод пользовательского меню, вызов доступных методов для генерации и преобразования строки, и вывод результата
         */

        static void Main(string[] args)
        {
            AlphabetSort  Obj    = new AlphabetSort();
            StrBuilder    genStr = new StrBuilder();
            Tester        test1  = new Tester();
            NullStrTester test5  = new NullStrTester();
            StrPrinter    msg    = new StrPrinter();
            char          key;
            string        text, res;
            bool          f = true;
            bool          b, t;

            while (f == true)
            {
                StrPrinter.OutputMenu();
                key = StrPrinter.InputKey();
                switch (key)
                {
                case '1':
                    StrPrinter.OutputEnterText();
                    text = StrPrinter.InputString();
                    b    = test5.TestNullStr(text);
                    if (b == true)
                    {
                        res = Obj.Sort(text);
                        StrPrinter.OutputResult(res);
                    }
                    else
                    {
                        StrPrinter.NullStrException();
                        goto case '1';
                    }
                    break;

                case '2':
                    Console.Clear();
                    text = genStr.StrBuild(msg.alphabet, 141, 7);
                    StrPrinter.OutputGenText(text);
                    res = Obj.Sort(text);
                    StrPrinter.OutputResult(res);
                    StrPrinter.Pause();
                    break;

                case '3':
                    StrPrinter.OutputTestsMenu();
                    key = StrPrinter.InputKey();
                    if (key == '1')
                    {
                        t = test1.TestMod();
                        StrPrinter.OutputTestRes(t);
                        StrPrinter.Pause();
                    }
                    else if (key == '2')
                    {
                        t = test1.TestGen();
                        StrPrinter.OutputTestRes(t);
                        StrPrinter.Pause();
                    }
                    else
                    {
                        StrPrinter.OutputWrongNumberException();
                        StrPrinter.Pause();
                        goto case '3';
                    }
                    break;

                case '4':
                    Console.Clear();
                    f = false;
                    break;

                default:
                    StrPrinter.OutputWrongNumberException();
                    StrPrinter.Pause();
                    break;
                }
            }
        }