// March 13, 2013 19:19:01 Wu xinqiang using System; using System. collections. generic; using System. linq; using System. diagnostics; using System. IO; namespace Chapter3_SelectionSort {class CArray {static void Main (string [] args) {CArray ca = new CArray (10); Timing tObj = new Timing (); random random = new Random (100); // Random number for (int I = 0; I <10; I ++) {ca. insert (random. next (0,100);} Console. writeLine ("SelectionSort Before Sorting:"); // Console Before Sorting. writeLine (); ca. displayElements (); // display the data Console. writeLine (); // line feed tObj. startTime (); // test the Console at the start time of the sorting time. writeLine (); Console. writeLine ("SelectionSort During Sorting:"); // Console in Sorting. writeLine (); ca. selectionSort (); // call the select sort method to sort the Console. writeLine (); tObj. stopTime (); // test the end time of the sorting time Console. writeLine ("SelectionSort After Sorting:"); // Console After Sorting. writeLine (); ca. displayElements (); // display the data Console. writeLine (); Console. writeLine ("SelectionSort time (. net): "+ tObj. result (). totalMilliseconds + "MS"); // display the total time used by the sorting method. writeLine (); ca. clear ();} public void SelectionSort () // select the sorting method {int temp, min; for (int outer = 0; outer <= upper; outer ++) {min = outer; for (int inner = outer + 1; inner <= upper; inner ++) {if (array [inner] <array [min]) {min = inner;} temp = array [outer]; array [outer] = array [min]; array [min] = temp;} this. displayElements () ;}} private int [] array; private int upper; private int numElements; public CArray (int Size) {array = new int [Size]; upper = Size-1; // maximum upper length numElements = 0; // array variable} public void Insert (int item) {array [numElements] = item; numElements ++ ;} public void DisplayElements () // display data {for (int I = 0; I <= upper; I ++) Console. write (array [I] + "");} public void Clear () // delete data {for (int I = 0; I <upper; I ++) {array [I] = 0; numElements = 0 ;}} public class Timing // time test class {TimeSpan duration; public Timing () {duration = new TimeSpan (0 );} public void StopTime () {duration = Process. getCurrentProcess (). totalProcessorTime;} public void StartTime () {GC. collect (); GC. waitForPendingFinalizers ();} public TimeSpan Result () {return duration ;}}/ * class CArray {private int [] array; private int upper; private int numElements; public CArray (int Size) {array = new int [Size]; upper = Size-1; numElements = 0;} public void Insert (int item) {array [numElements] = item; numElements ++;} public void DisplayElements () {for (int I = 0; I <= upper; I ++) Console. writeLine (array [I] + "");} public void Clear () {for (int I = 0; I <upper I ++) {array [I] = 0; numElements = 0 ;}}}*/experiment results: