Synchronization of old projects
Part1
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
namespace Lesson
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Print(int[] arr)
|
||||
{
|
||||
for (int i = 0; i < arr.Length; i++)
|
||||
{
|
||||
Console.Write(arr[i] + " ");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
#region 知识点一 基本原理
|
||||
//新建中间商
|
||||
//依次比较
|
||||
//找出极值(最大或最小
|
||||
//放入目标位置
|
||||
//比较n轮
|
||||
#endregion
|
||||
|
||||
#region 知识点二
|
||||
//实现升序 把 大的 放在最后面
|
||||
int[] arr = new int[] { 8, 7, 1, 5, 4, 2, 6, 3, 9 };
|
||||
Print(arr);
|
||||
////第一步 声明一个中间商 来记录索引
|
||||
////每一轮开始 默认第一个都是极值
|
||||
//int index = 0;
|
||||
//第二步
|
||||
//依次比较
|
||||
//for (int n = 1; n < arr.Length; n++)
|
||||
//{
|
||||
// //第三步
|
||||
// //找出极值(最大值)
|
||||
// if (arr[index] < arr[n])
|
||||
// {
|
||||
// index = n;
|
||||
// }
|
||||
//}
|
||||
|
||||
////第四步 放入目标位置
|
||||
////Length - 1 - 轮数
|
||||
////如果当前极值所在位置 就是目标位置 那就没必要交换了
|
||||
//if (index < arr.Length - 1 - 轮数)
|
||||
//{
|
||||
// int temp = arr[index];
|
||||
// arr[index] = arr[arr.Length - 1 -轮数];
|
||||
// arr[arr.Length - 1 - 轮数] = temp;
|
||||
//}
|
||||
|
||||
//第五步 比较m轮
|
||||
for (int m = 0; m < arr.Length; m++)
|
||||
{
|
||||
int index = 0;
|
||||
for (int n = 1; n < arr.Length - m; n++)
|
||||
{
|
||||
if (arr[index] < arr[n])
|
||||
{
|
||||
index = n;
|
||||
}
|
||||
}
|
||||
|
||||
if (index < arr.Length - 1 - m)
|
||||
{
|
||||
int temp = arr[index];
|
||||
arr[index] = arr[arr.Length - 1 - m];
|
||||
arr[arr.Length - 1 - m] = temp;
|
||||
}
|
||||
}
|
||||
Print(arr);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user