示例#1
0
        /*
         * This method will return the argument "arr" as an object of MyStack type.
         */
        public MyStack GetStackOf(int[] arr)
        {
            if (arr == null)
            {
                throw new ArgumentNullException();
            }
            MyStack ms = null;

            ms = new MyStack(100);
            for (int i = 0; i < arr.Length; ++i)
            {
                ms.push(arr[i]);
            }
            return(ms);
        }
示例#2
0
        static void Main()
        {
            int[] a  = { 0, 7, -3, 4, 29, 29, -10, 29, 29, 8 };
            int[] b  = { 0, 7, -3, 4, 29, 29, -10, 29, 29, 8 };
            int[] aa = { 5, -8, 30, 13, 0, 12, 5, 6, 8, 5 };

            try
            {
                //Initialising the object "h" with array "a" by using constructor of class Handler.
                Handler h = new Handler(a);

                //Searching the index of "inum" in array "a" after in array "b".

                int inum = 29;

                Console.WriteLine("\nThe index of " + inum + " in array \"a\" is " + h.SearchIndexOf(inum, h.Get_HandlArr()));
                Console.WriteLine("\nThe index of " + inum + " in array \"b\" is " + h.SearchIndexOf(inum, b) + "\n");

                //Sorting the array "a" as the given attribute of object "h" (by using "Get_HandlArr()" method).
                h.Sort(h.Get_HandlArr());
                //Sorting the array "b", which elements are equal to elements of array "a".
                h.Sort(b);

                Console.WriteLine("The sorted array \"a\" and the sorted array \"b\" \n");
                for (int i = 0; i < b.Length; ++i)
                {
                    Console.WriteLine("{0,3}   {1,3}", a[i], b[i]);
                }
                Console.WriteLine();

                //Setting the new attribute for object "h".
                h.Set_Data(aa);

                Console.WriteLine("The new attribute's (by using the method \"Set_Data(\"aa\")\") elements are\n");
                for (int i = 0; i < h.Get_HandlArr().Length; ++i)
                {
                    Console.Write(h.Get_HandlArr()[i] + " ");
                }
                Console.WriteLine("\n");

                //Sorting the array "aa" as the given attribute of object "h" (by using "Get_HandlArr()" method).
                h.Sort(h.Get_HandlArr());

                Console.WriteLine("The sorted attribute of object \"h\"\n  1. by using name of array \"aa\"");
                Console.WriteLine("  2. by using the method \"Get_HandlArr()\" \n");
                for (int i = 0; i < h.Get_HandlArr().Length; ++i)
                {
                    Console.WriteLine("{0,3} {1,3}", aa[i], h.Get_HandlArr()[i]);
                }

                Console.WriteLine("\n");

                //Sorting the array "aa".
                h.Sort(aa);

                Console.WriteLine("The sorted array \"aa\" is \n");
                for (int i = 0; i < aa.Length; ++i)
                {
                    Console.Write("{0,3} ", aa[i]);
                }
                Console.WriteLine("\n");

                //Getting the attribute of object "h" as a Stack by using the "GetStackOf()" method.
                MyStack attrStack = h.GetStackOf(h.Get_HandlArr());

                //Printing the Stack with "h" object's attribute ("handl") elements.
                Console.WriteLine("\nThe Stack with \"h\" object's attribute (\"handl\") elements is\n");
                while (attrStack.getSize() != 0)
                {
                    Console.Write(attrStack.pop() + " ");
                }
                Console.WriteLine();

                //Getting the array "aa" as a Scack by using the "GetStackOf()" method.
                MyStack aaStack = h.GetStackOf(aa);

                //Printing the Stack with elements of array "aa".
                Console.WriteLine("\nThe Stack with elements of array \"aa\" is\n");
                while (aaStack.getSize() != 0)
                {
                    Console.Write(aaStack.pop() + " ");
                }
                Console.WriteLine("\n");
            }
            catch (Exception e) { Console.WriteLine("\n" + e.Message + "\n" + e.StackTrace + "\n"); }
        }