hamzajaved

Selection_sort

Dec 11th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. //Selection Sort
  2.             int[] arr = { 34, 11, 67, 8, 9 };
  3.             int temp;
  4.             for (int i = 0; i < arr.Length-1; i++)
  5.             {
  6.                 int min_index = i;
  7.                 for (int j = i+1; j < arr.Length; j++)
  8.                 {
  9.                     if(arr[j] < arr[min_index])
  10.                     {
  11.                         temp = arr[j];
  12.                         arr[j] = arr[min_index];
  13.                         arr[min_index] = temp;
  14.                     }
  15.                 }
  16.             }
  17.  
  18.             for (int k = 0; k < arr.Length; k++)
  19.             {
  20.                 Console.WriteLine(arr[k]);
  21.             }
Add Comment
Please, Sign In to add comment