Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add c# insert in InsertionSort #689

Merged
merged 3 commits into from
Jan 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add C# insert in InsertioneSort
  • Loading branch information
PeixiZ committed Jan 26, 2022
commit c972adb7a08941bf3416e67e0627bb517c46614e
38 changes: 38 additions & 0 deletions basic/sorting/InsertionSort/InsertionSort.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Diagnostics;
using static System.Console;
namespace Pro;
public class Program
{
public static void Main()
{
int[] test = new int[]{31,12,10,5,6,7,8,10,23,34,56,43,32,21};
InsertSortNums(test);
foreach (var item in test)
{
WriteLine(item);
}
}
public static void InsertSortNums(int[] nums)
{
for(int initial = 1; initial < nums.Length; initial++)
{
WriteLine($"initial {initial} start");
for(int second_sort = 0; second_sort < initial; second_sort++)
{
WriteLine($"second {second_sort} start");
if(nums[second_sort] > nums[initial])
{
swap(ref nums[second_sort], ref nums[initial]);
WriteLine($"swap index is {second_sort}");
}
}
}
}

private static void swap(ref int compare_left, ref int compare_right)
{
int temp = compare_left;
compare_left = compare_right;
compare_right = temp;
}
}