示例#1
0
文件: Program.cs 项目: akry1/Dotnet
        /// <summary>
        /// Main method which takes the input and invoke methods in other classes to find the i largest elements in an array
        /// Also accepts the i size from command prompt
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            int[] sample = createArray();
            int length = sample.Length;
            int[] copy = new int[length];
            Array.Copy(sample, copy, length);

            int output;
            Console.Write("Enter the size of the output:");
            CommonClass.CheckInput(out output );

            int display;
            Console.Write("Click Enter to continue\n" + "or Enter 1 to display the detailed report of Input and Original sorted arry for all the programs:");
            string input = Console.ReadLine();
            if (Int32.TryParse(input, out display)) {}
            else display = 0;

            int resLength = output;
            if (length < resLength)
                resLength = length;
            int[] result = new int[resLength];

            CommonClass.resultSize = resLength;

            LinearSearchProgram linearSearchObject = new LinearSearchProgram();

            Console.WriteLine("==========LINEAR SEARCH==========");
            Console.WriteLine(); Console.WriteLine();
            Console.WriteLine("Random Array with {0} elements", length);
            CommonClass.DisplayArray(sample);

            CommonClass.numberOfAssignments = 0;

            result = linearSearchObject.LinearSearch(sample, resLength);

            //Console.WriteLine("==========LINEAR SEARCH OUTPUT==========");
            Console.WriteLine("Select Top {0} elements", resLength);
            CommonClass.DisplayArray(result);
            CommonClass.DisplayNoOfOperartions();

            //Display the sorted output of Linear search
            if (display == 1)
            {
                Console.WriteLine("Original Sorted Array", length);
                sample = linearSearchObject.LinearSearch(sample, length);
                CommonClass.DisplayArray(sample);
            }

            Array.Copy(copy, sample, length);

            MergeSortProgram mergeSortObject = new MergeSortProgram();

            Console.WriteLine("==========MERGE SORT==========");
            Console.WriteLine(); Console.WriteLine();

            //Display the input array for Merge sort
            if (display == 1)
            {
                Console.WriteLine("Random Array with {0} elements", length);
                CommonClass.DisplayArray(sample);
            }

            CommonClass.numberOfAssignments = 0;

            mergeSortObject.MergeSort(sample,0, length);
            result = CommonClass.largestIElements(sample, resLength);

            Console.WriteLine("Select Top {0} elements", resLength);
            CommonClass.DisplayArray(result);
            CommonClass.DisplayNoOfOperartions();

            //Display the sorted output of Merge Sort
            if (display == 1)
            {
                Console.WriteLine("Original Sorted Array", length);
                CommonClass.DisplayArray(sample);
            }

            Array.Copy(copy, sample, length);

            HeapSortProgram heapSortObject = new HeapSortProgram();

            Console.WriteLine("==========HEAP SORT==========");
            Console.WriteLine(); Console.WriteLine();

            //Display the input array for heap sort
            if (display == 1)
            {
                Console.WriteLine("Random Array with {0} elements", length);
                CommonClass.DisplayArray(sample);
            }

            CommonClass.numberOfAssignments = 0;
            result = heapSortObject.largestIElements(sample, resLength);

            Console.WriteLine("Select Top {0} elements", resLength);
            CommonClass.DisplayArray(result);
            CommonClass.DisplayNoOfOperartions();

            //Display the sorted output of Heap Sort
            if (display == 1)
            {
                sample = heapSortObject.largestIElements(sample, length);
                Console.WriteLine("Original Sorted Array", length);
                CommonClass.DisplayArray(sample);
            }

            Array.Copy(copy, sample, length);

            QuickSortProgram quickSortObject = new QuickSortProgram();

            Console.WriteLine("==========QUICK SORT==========");
            Console.WriteLine(); Console.WriteLine();

            //Display the input array for quicksort
            if (display == 1)
            {
                Console.WriteLine("Random Array with {0} elements", length);
                CommonClass.DisplayArray(sample);
            }

            CommonClass.numberOfAssignments = 0;
            quickSortObject.QuickSort(sample,0,length-1);
            result = CommonClass.largestIElements(sample, resLength);

            Console.WriteLine("Select Top {0} elements", resLength);
            CommonClass.DisplayArray(result);
            CommonClass.DisplayNoOfOperartions();

            //Display the sorted output of Quick Sort
            if (display == 1)
            {
                Console.WriteLine("Original Sorted Array", length);
                CommonClass.DisplayArray(sample);
            }

            Console.Read();
        }
示例#2
0
文件: Program.cs 项目: akry1/Dotnet
        /// <summary>
        /// Main method which takes the input and invoke methods in other classes to find the i largest elements in an array
        /// Also accepts the i size from command prompt
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            int[] sample = createArray();
            int   length = sample.Length;

            int[] copy = new int[length];
            Array.Copy(sample, copy, length);

            int output;

            Console.Write("Enter the size of the output:");
            CommonClass.CheckInput(out output);

            int display;

            Console.Write("Click Enter to continue\n" + "or Enter 1 to display the detailed report of Input and Original sorted arry for all the programs:");
            string input = Console.ReadLine();

            if (Int32.TryParse(input, out display))
            {
            }
            else
            {
                display = 0;
            }

            int resLength = output;

            if (length < resLength)
            {
                resLength = length;
            }
            int[] result = new int[resLength];

            CommonClass.resultSize = resLength;


            LinearSearchProgram linearSearchObject = new LinearSearchProgram();

            Console.WriteLine("==========LINEAR SEARCH==========");
            Console.WriteLine(); Console.WriteLine();
            Console.WriteLine("Random Array with {0} elements", length);
            CommonClass.DisplayArray(sample);

            CommonClass.numberOfAssignments = 0;

            result = linearSearchObject.LinearSearch(sample, resLength);

            //Console.WriteLine("==========LINEAR SEARCH OUTPUT==========");
            Console.WriteLine("Select Top {0} elements", resLength);
            CommonClass.DisplayArray(result);
            CommonClass.DisplayNoOfOperartions();

            //Display the sorted output of Linear search
            if (display == 1)
            {
                Console.WriteLine("Original Sorted Array", length);
                sample = linearSearchObject.LinearSearch(sample, length);
                CommonClass.DisplayArray(sample);
            }

            Array.Copy(copy, sample, length);

            MergeSortProgram mergeSortObject = new MergeSortProgram();

            Console.WriteLine("==========MERGE SORT==========");
            Console.WriteLine(); Console.WriteLine();


            //Display the input array for Merge sort
            if (display == 1)
            {
                Console.WriteLine("Random Array with {0} elements", length);
                CommonClass.DisplayArray(sample);
            }

            CommonClass.numberOfAssignments = 0;

            mergeSortObject.MergeSort(sample, 0, length);
            result = CommonClass.largestIElements(sample, resLength);

            Console.WriteLine("Select Top {0} elements", resLength);
            CommonClass.DisplayArray(result);
            CommonClass.DisplayNoOfOperartions();

            //Display the sorted output of Merge Sort
            if (display == 1)
            {
                Console.WriteLine("Original Sorted Array", length);
                CommonClass.DisplayArray(sample);
            }

            Array.Copy(copy, sample, length);

            HeapSortProgram heapSortObject = new HeapSortProgram();

            Console.WriteLine("==========HEAP SORT==========");
            Console.WriteLine(); Console.WriteLine();

            //Display the input array for heap sort
            if (display == 1)
            {
                Console.WriteLine("Random Array with {0} elements", length);
                CommonClass.DisplayArray(sample);
            }

            CommonClass.numberOfAssignments = 0;
            result = heapSortObject.largestIElements(sample, resLength);


            Console.WriteLine("Select Top {0} elements", resLength);
            CommonClass.DisplayArray(result);
            CommonClass.DisplayNoOfOperartions();

            //Display the sorted output of Heap Sort
            if (display == 1)
            {
                sample = heapSortObject.largestIElements(sample, length);
                Console.WriteLine("Original Sorted Array", length);
                CommonClass.DisplayArray(sample);
            }

            Array.Copy(copy, sample, length);

            QuickSortProgram quickSortObject = new QuickSortProgram();

            Console.WriteLine("==========QUICK SORT==========");
            Console.WriteLine(); Console.WriteLine();

            //Display the input array for quicksort
            if (display == 1)
            {
                Console.WriteLine("Random Array with {0} elements", length);
                CommonClass.DisplayArray(sample);
            }

            CommonClass.numberOfAssignments = 0;
            quickSortObject.QuickSort(sample, 0, length - 1);
            result = CommonClass.largestIElements(sample, resLength);

            Console.WriteLine("Select Top {0} elements", resLength);
            CommonClass.DisplayArray(result);
            CommonClass.DisplayNoOfOperartions();

            //Display the sorted output of Quick Sort
            if (display == 1)
            {
                Console.WriteLine("Original Sorted Array", length);
                CommonClass.DisplayArray(sample);
            }


            Console.Read();
        }