Advertisement
cortez

Selection Sort

Jun 29th, 2013
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2.  
  3. namespace SelectionSort
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] array = {5, 7, 5, 9, 342, 65, 234, 64, 32};
  10.             int positionEnd = array.Length - 1;
  11.         int temp;
  12.  
  13.             for (int i = 0; i < positionEnd; i++)
  14.             {
  15.                 if (array[i] > array[i + 1])
  16.                 {
  17.                     temp = array[i];
  18.             array[i] = array[i + 1];
  19.             array[i + 1] = temp;
  20.  
  21.                     if (i != 0)
  22.                     {
  23.                         if (array[i - 1] > array[i])
  24.                         {
  25.                             i -= 2;
  26.  
  27.                         }
  28.                     }
  29.                     else
  30.                     {
  31.                         continue;
  32.                     }
  33.                 }
  34.                 else
  35.                 {
  36.                     continue;
  37.                 }
  38.             }
  39.             foreach (int num in array)
  40.             {
  41.                 Console.Write(num + ",");
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement