SHARE
TWEET

Untitled

a guest Jun 25th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void SelectionSort() // ascending order
  2. {
  3.  
  4.     for (int i = 1; i <= List.Count; i++) // go through the list
  5.     {
  6.         ListClass minimum = (ListClass)List[i-1];
  7.         int min = i - 1;
  8.         for (int j = i;j <= List.Count-1; j++)
  9.         {
  10.             ListClass cur = (ListClass)List[j];
  11.  
  12.             if (minimum.getNum() > cur.getNum())
  13.                 min = j; // min equals smallest in list j
  14.  
  15.         }
  16.         swap(List, i-1, min);
  17.     }
  18.     Console.WriteLine("Array after selection sort: ");
  19.     foreach (ListClass cur in List)
  20.     {
  21.         cur.Display();
  22.     }
  23. public static void swap(ArrayList List, int x, int y)
  24. {
  25.     object temp = List[x];
  26.     List[x] = List[y];
  27.     List[y] = temp;
  28. }
  29. public void Display()
  30. {
  31.     foreach (ListClass cur in List)
  32.     {
  33.         cur.Display();
  34.     }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top