-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertionSort-Part1.cs
More file actions
48 lines (44 loc) · 1.26 KB
/
Copy pathInsertionSort-Part1.cs
File metadata and controls
48 lines (44 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
class Solution {
// Complete the insertionSort1 function below.
static void insertionSort1(int n, int[] arr) {
var i = n - 1;
var elem = arr[i];
while (i > 0)
{
i--;
if (arr[i] > elem)
{
arr[i + 1] = arr[i];
Console.WriteLine("{0}", string.Join(" ", arr));
}
else
{
arr[i + 1] = elem;
Console.WriteLine("{0}", string.Join(" ", arr));
return;
}
}
//@here means that position is first
arr[i] = elem;
Console.WriteLine("{0}", string.Join(" ", arr));
}
static void Main(string[] args) {
int n = Convert.ToInt32(Console.ReadLine());
int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), arrTemp => Convert.ToInt32(arrTemp))
;
insertionSort1(n, arr);
}
}