給一個有序數(shù)列插入整數(shù),依然按序排列

string a = Console.ReadLine();//用字符串接收用戶輸入的數(shù)據(jù)
string[] b = a.Split(" ");/*創(chuàng)建一個字符數(shù)組,并用空格分割(用戶輸入的時候就得自己用空格? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?*隔開)*/?
int[] c = new int[b.Length];//創(chuàng)建一個字符數(shù)組(因為要比大小,所以得用int數(shù)組)
for (int i = 0; i < b.Length; i++)//第一個循環(huán),把字符串數(shù)組轉(zhuǎn)換成數(shù)據(jù)數(shù)組
{??c[i] = Convert.ToInt32(b[i])? ;??}
int num = Convert.ToInt32(Console.ReadLine());
int di =?0;/*=0是正常情況。如果輸入的數(shù),比數(shù)組所有的數(shù)都大,就要放到數(shù)組最后一位。? ??? ? ? ? ? ? ?*那么代碼就得這么寫:int?di =?c.Length - 1?;
? ? ? ? ? ? ? ?*/
if?(num < c[0])//假如輸入的數(shù)據(jù)是0,或者說比數(shù)組所有的數(shù)都小,就執(zhí)行這個。
{? di = -1 ;? }
for (int i = 0; i < c.Length-1; i++)/*第二個循環(huán),找到要插入的地方。
{? if (num >= c[i] & num <= c[i + 1] )? ?
? ? ?? { di = i ;?break?;}
}
int[] d = new int[c.Length + 1];//創(chuàng)建一個新數(shù)組,用來接收原數(shù)組移過來的數(shù)
for (int i = 0; i < di+1; i++)//第三個循環(huán),把第一批數(shù)據(jù)移過去。如果輸入的數(shù)據(jù)是0,
{? ?d[i] = c[i] ;? }//那么這個循環(huán)就不會執(zhí)行,因為不滿足條件。i=0,又要小于0,不滿足。
d[di+1] = num;//把數(shù)插進去
for (int i = di+1; i < c.Length; i++)//第四個循環(huán),把第二批數(shù)據(jù)移過去。
{? ?d[i + 1] = c[i] ;? ?}//如果輸入的數(shù)據(jù)是0,那么會直接執(zhí)行這個循環(huán)。
foreach (int temp in d)
{??Console.Write(temp) ; }
==============================================================