Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Insertion_Sort
- {
- class Program
- {
- const int SIZE = 10;
- public static void Sorting(int[] a)
- {
- int PrintCounter = 1;
- for (int i = 0; i < a.Length; i++)
- {
- Console.Write("Enter a number: ");
- a[i] = int.Parse(Console.ReadLine());
- MoveLeft(a, i);
- OutPut(a, PrintCounter);
- PrintCounter++;
- }
- }
- public static void MoveLeft(int[] a, int place)
- {
- int temp;
- while ((place != 0)&&(a[place] < a[place - 1]))
- {
- temp = a[place];
- a[place] = a[place - 1];
- a[place - 1] = temp;
- place--;
- }
- }
- public static void OutPut(int[] a, int mone)
- {
- for (int i = 0; i < mone; i++)
- {
- Console.Write(a[i]+" ");
- }
- Console.WriteLine();
- }
- static void Main(string[] args)
- {
- int [] a=new int[SIZE];
- Sorting(a);
- }
- }
- }
Add Comment
Please, Sign In to add comment