Guest User

Untitled

a guest
Jun 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace Insertion_Sort
  8. {
  9.     class Program
  10.     {
  11.         const int SIZE = 10;
  12.  
  13.         public static void Sorting(int[] a)
  14.         {
  15.             int PrintCounter = 1;
  16.             for (int i = 0; i < a.Length; i++)
  17.             {
  18.                 Console.Write("Enter a number: ");
  19.                 a[i] = int.Parse(Console.ReadLine());
  20.                     MoveLeft(a, i);
  21.                 OutPut(a, PrintCounter);
  22.                 PrintCounter++;
  23.             }
  24.         }
  25.  
  26.         public static void MoveLeft(int[] a, int place)
  27.         {
  28.             int temp;
  29.             while ((place != 0)&&(a[place] < a[place - 1]))
  30.             {
  31.                 temp = a[place];
  32.                 a[place] = a[place - 1];
  33.                 a[place - 1] = temp;
  34.                 place--;
  35.             }
  36.         }
  37.  
  38.         public static void OutPut(int[] a, int mone)
  39.         {
  40.             for (int i = 0; i < mone; i++)
  41.             {
  42.                 Console.Write(a[i]+" ");
  43.             }
  44.             Console.WriteLine();
  45.         }
  46.  
  47.         static void Main(string[] args)
  48.         {
  49.             int [] a=new int[SIZE];
  50.             Sorting(a);
  51.                
  52.         }
  53.     }
  54. }
Add Comment
Please, Sign In to add comment