[Moved from article Gushared.com] "time" the little things that sometimes we may have overlooked. Time program administrator that was not enough to do the program, it will take much work. But when it comes to work: I'm A Requirement want the program to work within 2 minutes * o * Wow I'm going to do this! I programmed it so calculating chores. Finally, the admin would have to look at the timer. What part is it takes a lot. Then the new algorithm. But the point is We would like the timer is not it? I would say I am the admin Stopwatch many people might know already. Many people never think to use it Stopwatch class is attached to. NET Framework is just waiting for us to run it, we use it primarily starts the timer stops and watch the time count. Admin is just this preview: Hahah using System.Diagnostics; / / Do not forget! Stopwatch sw = new Stopwatch (); / / To run the class Stopwatch sw.Start (); / / Start the timer sw.Stop (); / / Stop the timer sw.Elapsed; / / Retrieve the time value format counted TimeSpan (Hours: biglots Minutes: Seconds.Milliseconds) sample program. Compare the performance of the Selection Sort Insertion biglots Sort PS. Console Application that will program will consist of four method is / / 1.Main / / method main run. To use the other method static void Main (string [] args) {for (int i = 0; i <20; i + +) {int [] arr = RandomArray (); Console.Write ("Insertion Sort:" + InsertionSort (. arr)); Console.Write ("Selection Sort:" + SelectionSort (arr)); Console.WriteLine ();} Console.Read ();} / / 2.RandomArray. / / Method for random values from 0 to 100, put in array 100 / / to be used for testing to sort the array and 2 static int [] RandomArray () {int [] arr = new int [100. ]; for (int i = 0; i <arr.Length; i + +) {Random ran = new Random (); arr [i] = ran.Next (0, 100); Thread.Sleep (10);} return arr. ;} / / 3.InsertionSort / / method to sort data Insertion Sort static TimeSpan InsertionSort (int [] arr) {int j; int index; Stopwatch SW = new Stopwatch (); SW.Start (); for (int i. = 1; i 0) && (arr [j - 1]> index)) {arr [j] = arr [j - 1]; j = j - 1;} arr [j] = index;} SW.Stop (. ); return SW.Elapsed;} / / 4.SelectionSort / / method to sort the Selection Sort static biglots TimeSpan SelectionSort (int [] arr) {int min, temp; Stopwatch SW = new Stopwatch (); SW.Start (). ; for (int i = 0; i <arr.Length - 1; i + +) {min = i; for (int j = i + 1; j <arr.Length; j + +) {if (arr [j] <arr [. min]) {min = j;}} temp = arr [i]; arr [i] = arr [min]; arr [min] = temp;} SW.Stop (); return SW.Elapsed;} program output.
Of results will be made better time than Insertion sort Selection sort of a Stopwatch timer with further biglots studies. dotnetperls.com
7-11 300 stamp bags review of the apps on the comparison Flat Design iOS7 VS WP8 Stored Procedures is? Examples of use Triggers on SQL Server [C #] timing of the program is that we want to change the Cursor in C # I Like Page Add redeemed us! Triggers if I do she have to do with it! Empty Textbox background color change biglots with jQuery JFrame not do?
Python c # Programming Tips General Python SQL Server java programming biglots Java HTML Database Google API Android CSS CSS3 Review blog HTML5 Problem SEO Windows CE jQuery solution.
No comments:
Post a Comment