SIGN IN SIGN UP
doocs / leetcode UNCLAIMED

🔥LeetCode solutions in any programming language | 多种编程语言实现 LeetCode、《剑指 Offer(第 2 版)》、《程序员面试金典(第 6 版)》题解

0 0 15 Java
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++)
{
for (int second_sort = 0; second_sort < initial; second_sort++)
{
if (nums[second_sort] > nums[initial])
{
swap(ref nums[second_sort], ref nums[initial]);
}
}
}
}
private static void swap(ref int compare_left, ref int compare_right)
{
int temp = compare_left;
compare_left = compare_right;
compare_right = temp;
}
}