using System; using System.Collections.Generic; using System.Linq; using System.Security.AccessControl; using System.Text; using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
//循环 冒泡排序 对一组杂乱的数据进行大小排序
//第一轮比对完之后 确定了一个最大的数。已经确定的数就不用再比对了
//以后每一轮对比都确定一个最大数,总共要比对多少轮 n-1轮
int[] arr = new int[] { 21, 12, 82, 32, 65, 43 };
//int temp = 0;
//for(int i = 0; i <= arr.Length-1; i++)
//{
// for (int j = 0; j <=arr.Length-1-i; j++)
// {
// if(arr[j] > arr[j+1])
// {
// temp = arr[j];
// arr[j] = arr[j+1];
// arr[j+1] = temp;
// }
// }
//}
//for ( int i= 0; i <= arr.Length; i++)
//{
// Console.WriteLine(arr[i]);
//}
Array.Sort(arr);
Console.WriteLine(String.Join(" ", arr));
//1 3 4 7 插入一个4
//首先要找到要插入的索引位置
//输入一组用空格隔开的数据
string str=Convert.ToString(Console.ReadLine());
string[] strArray = str.Split(" ");
int[] intArray1 = new int[strArray.Length];
for(int i = 0; i < strArray.Length; i++)
{
intArray1[i] = Convert.ToInt32(strArray[i]);
}
Array.Sort(intArray1);
//找到要插入的下标的位置
int m = 0;
int num=Convert.ToInt32(Console.ReadLine());
for(int i = 0; i < intArray1.Length; i++)
{
if(intArray1[i] <= num && num <= intArray1[i + 1])
{
m = i + 1;
}
}
//判断是不是比最后一个数
if (num >= intArray1[intArray1.Length - 1]) num = intArray1.Length;
//创建新的数组
int[] newArray = new int[intArray1.Length + 1];
for(int i = 0; i<m; i++)
{
newArray[i] = intArray1[i];
}
newArray[m] = num;
for(int i = 0; i < newArray.Length; i++)
{
newArray[i] = intArray1[i - 1];
}
}
}
}