Exemplo n.º 1
0
        static void MainNEW(string[] args)
        {
            IntBuffer buff = new IntBuffer(8);
            Producer  p    = new Producer(buff);
            Consumer  c    = new Consumer(buff);

            Thread producer = new Thread(new ThreadStart(p.Run));
            Thread consumer = new Thread(new ThreadStart(c.Run));

            producer.Start();
            consumer.Start();



            string aaa = "aa";
            string bbb = "bb";

            Console.WriteLine("aa={0}, bb={1}", aaa, bbb);
            Permutation.SwapUs <string>(ref aaa, ref bbb);
            Console.WriteLine("aa={0}, bb={1}", aaa, bbb);

            int[] arr = new int[] { 2, 3 };
            Console.WriteLine("arr[0]={0}, arr[1]={1}", arr[0], arr[1]);
            Permutation.SwapUs <int>(ref arr[0], ref arr[1]);
            Console.WriteLine("arr[0]={0}, arr[1]={1}", arr[0], arr[1]);


            // find first non repeating char
            string ss = "IKiNAKAP";

            Console.WriteLine("first distinct char is = '{0}'", FindFirstNonRepeatingChar2(ss));
            ////

            // In place string update.
            ss = "Battle of Vowels: Indiana Jones";
            Console.WriteLine(RemoveSelectedChars(ss, "aeiou"));

            // In place string reversal
            ss = "This is a test string.";
            Console.WriteLine(InPlaceStringReversal(ss));

            // Int to String
            ss = IntToString(284);
            ss = IntToString(-4484);
            ss = IntToString(0);
            ss = IntToString(+23);
            ss = IntToString(+0);

            // string to int
            int z = StringToInt("-4484");

            z = StringToInt("284");
            z = StringToInt("0");

            FindDupWithoutExtraBuffer("HELLO");

            // Permutation n!
            Permutation permutation = new Permutation();
            string      inStr       = "ABCD";

            // permutation.setper(inStr.ToCharArray());
            permutation.SetPermutation(inStr);

            permutation.SetCombi(inStr);



            // phone number combinations
            Console.WriteLine("phone number combinations");
            Console.WriteLine("------------------------------");
            //Console.WriteLine(PhoneNumberChars.GetChar(0, 0));
            //Console.WriteLine(PhoneNumberChars.GetChar(1, 0));
            //Console.WriteLine(PhoneNumberChars.GetChar(0, 1));
            //Console.WriteLine(PhoneNumberChars.GetChar(1, 1));
            //Console.WriteLine(PhoneNumberChars.GetChar(2, 3));
            //Console.WriteLine(PhoneNumberChars.GetChar(9, 1));
            //Console.WriteLine(PhoneNumberChars.GetChar(9, 0));

            permutation.SetPhoneCharConfig(new byte[] { 7, 4, 2, 3 });



            string[] xxx = new string[2];
            string[] yyy = new string[3];
            yyy[2] = "hello";
            xxx    = yyy;
            Console.WriteLine(xxx[2]);
            ///
            string aa = "barista";
            string bb = "far";

            char[] final = aa.ToCharArray();
            if (bb.Length <= aa.Length)
            {
                Array.Copy(bb.ToCharArray(), 0, final, 0, bb.Length);
            }
            Console.WriteLine(final);
            //
            //int[,] arr = new int[2, 3]; // [col, row]
            //arr[1, 2] = 20;

            Collections();
            string x = null;

            Console.WriteLine("reverse of empty = {0}", ReverseMe(string.Empty));
            Console.WriteLine("reverse of null = {0}", ReverseMe(x));
            x = "seetaphal";
            Console.WriteLine("reverse of x = {0}", ReverseMe(x));

            x = "this is seetaphal";
            Console.WriteLine("reverse of x = {0}", ReverseMe(x));
            Console.Read();

            MySingleLLNode head = MySingleLinkedList.CreateList(2);

            MySingleLinkedList.AddLast(head, 5);
            head = MySingleLinkedList.AddFirst(head, 1);
            head = MySingleLinkedList.AddAscOrder(head, 3);
            head = MySingleLinkedList.AddAscOrder(head, 7);
            head = MySingleLinkedList.AddAscOrder(head, 1);
            head = MySingleLinkedList.AddAscOrder(head, 6);
            head = MySingleLinkedList.AddAscOrder(head, 4);

            MySingleLinkedList.PrintList(head);

            MySingleLinkedList.DeleteMe(ref head, 1);  //delete First
            MySingleLinkedList.PrintList(head);
            MySingleLinkedList.DeleteMe(ref head, 7);  //delete last
            MySingleLinkedList.PrintList(head);
            MySingleLinkedList.DeleteMe(ref head, 59); //delete Non existent
            MySingleLinkedList.PrintList(head);
            MySingleLinkedList.DeleteMe(ref head, 5);  //delete 5
            MySingleLinkedList.PrintList(head);
            //MySingleLinkedList.DeleteMe(null, 1); //delete from Null

            MySingleLinkedList.PrintList(head);

            Console.Read();
        }
Exemplo n.º 2
0
        static void Main01(string[] args)
        {
            MainNEW(args);
            BitArray bitArr = new BitArray(int.MaxValue);

            CallTryCatch();
            //[67108864]

            //    Car[] cars = new Car[2];
            //    cars[0] = new Car("Nissan");
            //    cars[1] = new Car("Toyota");

            //    Swap(cars[0], cars[1]);
            // no change in array.


            BST binaryTree = new BST();

            //binaryTree.CreateTree(4);
            //int[] arr = new int[] { 2, 5, 1, 3, 7, 6, 9 };

            binaryTree.CreateTree(9);
            int[] arr = new int[] { 4, 14, 2, 5, 10, 1, 3, 7, 12, 6, 8, 11, 13 };

            foreach (int x in arr)
            {
                binaryTree.InsertNode(x);
            }

            binaryTree.PrintInorder();

            Console.WriteLine(binaryTree.Add('a', 'b'));
            Console.WriteLine("Now print PreOrder Ittv....");
            Console.WriteLine();
            binaryTree.PrintTree_PreOrder_Ittv(binaryTree.Root);

            binaryTree.PrintTree_InOrder_Ittv(binaryTree.Root);


            Console.WriteLine("Now print PostOrder Ittv....");
            Console.WriteLine();
            binaryTree.PrintTree_PostOrder_Ittv(binaryTree.Root);


            int i = 5;

            Console.WriteLine(i = i << 5);
            Console.WriteLine(i = i << 5);

            bool ss = CheckHasUniqueCharsUsingBitwise("abcdefghij");


            IntBuffer buff = new IntBuffer(4);
            Producer  p    = new Producer(buff);
            Consumer  c    = new Consumer(buff);

            Thread producer = new Thread(new ThreadStart(p.Run));
            Thread consumer = new Thread(new ThreadStart(c.Run));

            producer.Start();
            consumer.Start();
        }